17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/pubid/csa/identifiers/bundled.rb', line 17
def to_s
if base.is_a?(Cec)
prefix = base.publisher_prefix || "CSA"
needs_space = !prefix.end_with?("-")
year_display = if base.year
year_str = base.year.to_s
if year_str.length == 4 && year_str.start_with?("20")
year_str[2..3]
else
year_str
end
end
base_str = (needs_space ? "#{prefix} " : prefix) +
base.code.value.to_s + ":#{year_display}"
parts = [base_str]
else
parts = [base.to_s]
end
if bundled_with && !bundled_with.empty?
bundled_with.each do |bundled|
if bundled.is_a?(Cec)
bundled_part = bundled.code.value.to_s if bundled.year
separator = bundled.year_format == "dash" ? "-" : ":"
bundled_part += separator
bundled_part += bundled.year_prefix if bundled.year_prefix bundled_part += "F" if bundled.french && bundled.year_format != "dash" && !bundled.year_prefix
year_str = bundled.year.to_s
bundled_part += if year_str.length == 4 && year_str.start_with?("20")
year_str[2..3]
else
year_str
end
end
else
bundled_part = ""
bundled_part += bundled.code.to_s if bundled.code
if bundled.year
separator = bundled.year_format == "dash" ? "-" : ":"
bundled_part += separator
bundled_part += bundled.year_prefix if bundled.year_prefix bundled_part += "F" if bundled.french && bundled.year_format != "dash" && !bundled.year_prefix year_str = bundled.year.to_s
bundled_part += if bundled.class.attributes.key?(:original_year_4digit) && bundled.original_year_4digit
year_str
elsif year_str.length == 4 && year_str.start_with?("20")
year_str[2..3]
elsif year_str.length == 4 && year_str.start_with?("19") && bundled.class.attributes.key?(:original_year_4digit) && !bundled.original_year_4digit
year_str[2..3]
else
year_str
end
end
end
parts << bundled_part
end
end
result = parts.join(" + ")
if reaffirmation
year_was_2digit = base.class.attributes.key?(:original_year_4digit) && !base.original_year_4digit
reaffirmation_was_4digit = reaffirmation.to_s.length == 4 &&
reaffirmation.to_s.start_with?("19", "20")
result += if year_was_2digit && reaffirmation_was_4digit
" (R#{reaffirmation})"
else
"(R#{reaffirmation})"
end
end
result
end
|