Module: Cul::Hydra::Solrizer::ModsFieldable
- Extended by:
- ActiveSupport::Concern, ClassMethods
- Includes:
- Solrizer::DefaultDescriptors::Normal
- Included in:
- Datastreams::ModsDocument
- Defined in:
- lib/cul_hydra/solrizer/mods_fieldable.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- MODS_NS =
{'mods'=>'http://www.loc.gov/mods/v3'}
- ORIGIN_INFO_DATES =
["dateCreated", "dateIssued", "dateOther"]
Instance Method Summary collapse
- #all_subjects(node = mods) ⇒ Object
- #alternative_titles(node = mods) ⇒ Object
- #collections ⇒ Object
- #coordinates(node = mods) ⇒ Object
- #date_notes(node = mods) ⇒ Object
- #date_range_to_textual_date(start_year, end_year) ⇒ Object
- #dates(node = mods) ⇒ Object
- #durst_subjects(node = mods) ⇒ Object
- #formats(node = mods) ⇒ Object
- #item_in_context_url(node = mods) ⇒ Object
- #key_date_range(node = mods) ⇒ Object
- #languages_iso639_2_code ⇒ Object
- #languages_iso639_2_text ⇒ Object
- #main_title(node = mods) ⇒ Object
- #mods ⇒ Object
- #names(role_authority = nil, role = nil) ⇒ Object
- #non_date_notes(node = mods) ⇒ Object
- #non_item_in_context_url(node = mods) ⇒ Object
- #origin_info_place(node = mods) ⇒ Object
- #origin_info_place_for_display(node = mods) ⇒ Object
- #project_url(node = mods) ⇒ Object
- #projects ⇒ Object
- #repository_code(node = mods) ⇒ Object
- #repository_text(node = mods) ⇒ Object
- #shelf_locators(node = mods) ⇒ Object
- #sort_title(node = mods) ⇒ Object
- #sublocation(node = mods) ⇒ Object
- #textual_dates(node = mods) ⇒ Object
- #titles(node = mods) ⇒ Object
- #to_solr(solr_doc = {}) ⇒ Object
- #translate_project_title(project_title, type) ⇒ Object
- #translate_repo_marc_code(code, type) ⇒ Object
- #zero_pad_year(year) ⇒ Object
Methods included from ClassMethods
map_field, map_value, maps_field?, normalize, value_mapper
Instance Method Details
#all_subjects(node = mods) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 313 def all_subjects(node=mods) list_of_subjects = [] node.xpath("./mods:subject[not(@authority) or @authority != 'Durst']/mods:topic", MODS_NS).collect do |n| list_of_subjects << ModsFieldable.normalize(n.text, true) end node.xpath("./mods:subject/mods:geographic", MODS_NS).collect do |n| list_of_subjects << ModsFieldable.normalize(n.text, true) end node.xpath("./mods:subject/mods:name", MODS_NS).collect do |n| list_of_subjects << ModsFieldable.normalize(n.text, true) end node.xpath("./mods:subject/mods:temporal", MODS_NS).collect do |n| list_of_subjects << ModsFieldable.normalize(n.text, true) end node.xpath("./mods:subject/mods:titleInfo", MODS_NS).collect do |n| list_of_subjects << ModsFieldable.normalize(n.text, true) end node.xpath("./mods:subject/mods:genre", MODS_NS).collect do |n| list_of_subjects << ModsFieldable.normalize(n.text, true) end return list_of_subjects end |
#alternative_titles(node = mods) ⇒ Object
112 113 114 115 116 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 112 def alternative_titles(node=mods) node.xpath('./mods:titleInfo[@type and (@type="alternative" or @type="abbreviated" or @type="translated" or @type="uniform")]', MODS_NS).collect do |t| ModsFieldable.normalize(t.text) end end |
#collections ⇒ Object
62 63 64 65 66 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 62 def collections mods.xpath("./mods:relatedItem[@type='host' and @displayLabel='Collection']", MODS_NS).collect do |p_node| ModsFieldable.normalize(main_title(p_node), true) end end |
#coordinates(node = mods) ⇒ Object
368 369 370 371 372 373 374 375 376 377 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 368 def coordinates(node=mods) coordinate_values = [] node.xpath("./mods:subject/mods:cartographics/mods:coordinates", MODS_NS).collect do |n| n = ModsFieldable.normalize(n.text, true) if n.match(/-*\d+\.\d+\s*,\s*-*\d+\.\d+\s*/) # Expected coordinate format: 40.123456,-73.5678 coordinate_values << n end end coordinate_values end |
#date_notes(node = mods) ⇒ Object
269 270 271 272 273 274 275 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 269 def date_notes(node=mods) date_notes = [] node.xpath("./mods:note[@type = 'date' or @type = 'date source']", MODS_NS).collect do |n| date_notes << ModsFieldable.normalize(n.text, true) end return date_notes end |
#date_range_to_textual_date(start_year, end_year) ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 254 def date_range_to_textual_date(start_year, end_year) start_year = start_year.to_i.to_s # Remove zero-padding if present end_year = end_year.to_i.to_s # Remove zero-padding if present if start_year == end_year return [start_year] else return [('Between ' + (start_year.to_i > 0 ? start_year : start_year[1,start_year.length] + ' BCE') + ' and ' + (end_year.to_i > 0 ? (start_year.to_i > 0 ? end_year : end_year + ' CE') : end_year[1,end_year.length] + ' BCE') )] end end |
#dates(node = mods) ⇒ Object
145 146 147 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 145 def dates(node=mods) # get all the dateIssued with keyDate = 'yes', but not point = 'end' end |
#durst_subjects(node = mods) ⇒ Object
338 339 340 341 342 343 344 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 338 def durst_subjects(node=mods) list_of_subjects = [] node.xpath("./mods:subject[@authority='Durst']/mods:topic", MODS_NS).collect do |n| list_of_subjects << ModsFieldable.normalize(n.text, true) end return list_of_subjects end |
#formats(node = mods) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 149 def formats(node=mods) # get all the form values with authority != 'marcform' node.xpath("./mods:physicalDescription/mods:form[@authority != 'marcform']", MODS_NS).collect do |n| ModsFieldable.normalize(n.text) end end |
#item_in_context_url(node = mods) ⇒ Object
289 290 291 292 293 294 295 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 289 def item_in_context_url(node=mods) item_in_context_url_val = [] node.xpath("./mods:location/mods:url[@access='object in context']", MODS_NS).collect do |n| item_in_context_url_val << ModsFieldable.normalize(n.text, true) end item_in_context_url_val end |
#key_date_range(node = mods) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 234 def key_date_range(node=mods) dates = [] encodings = ['w3cdtf','iso8601'] ORIGIN_INFO_DATES.each do |element| encodings.each do |encoding| xpath = "./mods:originInfo/mods:#{element}[(@keyDate) and (@encoding = '#{encoding}')]" node.xpath(xpath, MODS_NS).collect do |n| range = [ModsFieldable.normalize(n.text, true)] if n['point'] != 'end' n.xpath("../mods:#{element}[(@encoding = '#{encoding}' and @point = 'end')]", MODS_NS).each do |ep| range << ModsFieldable.normalize(ep.text, true) end end dates << range end end end return dates.first || dates end |
#languages_iso639_2_code ⇒ Object
74 75 76 77 78 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 74 def languages_iso639_2_code mods.xpath("./mods:language/mods:languageTerm[@type='code' and @authority='iso639-2']", MODS_NS).collect do |n| ModsFieldable.normalize(n.text, true) end end |
#languages_iso639_2_text ⇒ Object
68 69 70 71 72 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 68 def languages_iso639_2_text mods.xpath("./mods:language/mods:languageTerm[@type='text' and @authority='iso639-2']", MODS_NS).collect do |n| ModsFieldable.normalize(n.text, true) end end |
#main_title(node = mods) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 94 def main_title(node=mods) # include only the untyped [!@type] titleInfo t = node.xpath('./mods:titleInfo[not(@type)]', MODS_NS).first if t ModsFieldable.normalize(t.text) else nil end end |
#mods ⇒ Object
52 53 54 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 52 def mods ng_xml.xpath('/mods:mods', MODS_NS).first end |
#names(role_authority = nil, role = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 118 def names(=nil, role=nil) # get all the name nodes # keep all child text except the role terms xpath = "./mods:name" unless .nil? xpath << "/mods:role/mods:roleTerm[@authority='#{.to_s}'" unless role.nil? xpath << " and normalize-space(text()) = '#{role.to_s.strip}'" end xpath << "]/ancestor::mods:name" end names = mods.xpath(xpath, MODS_NS).collect do |node| base_text = node.xpath('./mods:namePart', MODS_NS).collect { |c| c.text }.join(' ') ModsFieldable.normalize(base_text, true) end # Note: Removing subject names from name field extraction. # See: https://issues.cul.columbia.edu/browse/DCV-231 and https://issues.cul.columbia.edu/browse/SCV-102 #xpath = "./mods:subject" + xpath[1,xpath.length] #mods.xpath(xpath, MODS_NS).each do |node| # base_text = node.xpath('./mods:namePart', MODS_NS).collect { |c| c.text }.join(' ') # names << ModsFieldable.normalize(base_text, true) #end names end |
#non_date_notes(node = mods) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 277 def non_date_notes(node=mods) non_date_notes = [] node.xpath("./mods:note[not(@type) or (@type != 'date' and @type != 'date source' and @type != 'filename')]", MODS_NS).collect do |n| if n.attr('type') == 'view direction' non_date_notes << 'View Direction: ' + ModsFieldable.normalize(n.text, true) else non_date_notes << ModsFieldable.normalize(n.text, true) end end return non_date_notes end |
#non_item_in_context_url(node = mods) ⇒ Object
297 298 299 300 301 302 303 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 297 def non_item_in_context_url(node=mods) non_item_in_context_url_val = [] node.xpath("./mods:location/mods:url[not(@access='object in context')]", MODS_NS).collect do |n| non_item_in_context_url_val << ModsFieldable.normalize(n.text, true) end non_item_in_context_url_val end |
#origin_info_place(node = mods) ⇒ Object
346 347 348 349 350 351 352 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 346 def origin_info_place(node=mods) places = [] node.xpath("./mods:originInfo/mods:place/mods:placeTerm", MODS_NS).collect do |n| places << ModsFieldable.normalize(n.text, true) end return places end |
#origin_info_place_for_display(node = mods) ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 354 def origin_info_place_for_display(node=mods) # If there are multiple origin_info place elements, choose only the ones without valueURI attributes. Otherwise show the others. places_with_uri = [] places_without_uri = [] node.xpath("./mods:originInfo/mods:place/mods:placeTerm[@valueURI]", MODS_NS).collect do |n| places_with_uri << ModsFieldable.normalize(n.text, true) end node.xpath("./mods:originInfo/mods:place/mods:placeTerm[not(@valueURI)]", MODS_NS).collect do |n| places_without_uri << ModsFieldable.normalize(n.text, true) end return (places_without_uri.length > 0 ? places_without_uri : places_with_uri) end |
#project_url(node = mods) ⇒ Object
305 306 307 308 309 310 311 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 305 def project_url(node=mods) project_url_val = [] node.xpath("./mods:relatedItem[@type='host' and @displayLabel='Project']/mods:location/mods:url", MODS_NS).collect do |n| project_url_val << ModsFieldable.normalize(n.text, true) end project_url_val end |
#projects ⇒ Object
56 57 58 59 60 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 56 def projects mods.xpath("./mods:relatedItem[@type='host' and @displayLabel='Project']", MODS_NS).collect do |p_node| ModsFieldable.normalize(main_title(p_node), true) end end |
#repository_code(node = mods) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 156 def repository_code(node=mods) # get the location/physicalLocation[@authority = 'marcorg'] repo_code_node = node.xpath("./mods:location/mods:physicalLocation[@authority = 'marcorg']", MODS_NS).first if repo_code_node ModsFieldable.normalize(repo_code_node.text) else return nil end end |
#repository_text(node = mods) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 167 def repository_text(node=mods) # get the location/physicalLocation[not(@authority)] repo_text_node = node.xpath("./mods:location/mods:physicalLocation[not(@authority)]", MODS_NS).first if repo_text_node ModsFieldable.normalize(repo_text_node.text) else return nil end end |
#shelf_locators(node = mods) ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 204 def shelf_locators(node=mods) values = node.xpath("./mods:location/mods:shelfLocator", MODS_NS).collect do |n| ModsFieldable.normalize(n.text, true) end values += node.xpath("./mods:location/mods:holdingSimple/mods:copyInformation/mods:shelfLocator", MODS_NS).collect do |n| ModsFieldable.normalize(n.text, true) end values end |
#sort_title(node = mods) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 80 def sort_title(node=mods) # include only the untyped [!@type] titleInfo, exclude noSort base_text = '' t = node.xpath('./mods:titleInfo[not(@type)]', MODS_NS).first if t t.children.each do |child| base_text << child.text unless child.name == 'nonSort' end end base_text = ModsFieldable.normalize(base_text, true) base_text = nil if base_text.empty? base_text end |
#sublocation(node = mods) ⇒ Object
214 215 216 217 218 219 220 221 222 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 214 def sublocation(node=mods) values = node.xpath("./mods:location/mods:sublocation", MODS_NS).collect do |n| ModsFieldable.normalize(n.text, true) end values += node.xpath("./mods:location/mods:holdingSimple/mods:copyInformation/mods:sublocation", MODS_NS).collect do |n| ModsFieldable.normalize(n.text, true) end values end |
#textual_dates(node = mods) ⇒ Object
224 225 226 227 228 229 230 231 232 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 224 def textual_dates(node=mods) dates = [] ORIGIN_INFO_DATES.each do |element| node.xpath("./mods:originInfo/mods:#{element}[not(@keyDate) and not(@point) and not(@encoding)]", MODS_NS).collect do |n| dates << n.text.strip end end return dates end |
#titles(node = mods) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 104 def titles(node=mods) # all titles without descending into relatedItems # For now, this only includes the main title and selected alternate_titles all_titles = [] all_titles << main_title unless main_title.nil? all_titles += alternative_titles unless alternative_titles.nil? end |
#to_solr(solr_doc = {}) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 379 def to_solr(solr_doc={}) solr_doc = (defined? super) ? super : solr_doc return solr_doc if mods.nil? # There is no mods. Return because there is nothing to process, otherwise NoMethodError will be raised by subsequent lines. solr_doc["all_text_teim"] ||= [] solr_doc["title_si"] = sort_title solr_doc["title_ssm"] = titles solr_doc["alternative_title_ssm"] = alternative_titles solr_doc["all_text_teim"] += solr_doc["alternative_title_ssm"] solr_doc["lib_collection_sim"] = collections solr_doc["lib_name_sim"] = names solr_doc["lib_name_teim"] = solr_doc["lib_name_sim"] solr_doc["all_text_teim"] += solr_doc["lib_name_teim"] solr_doc["lib_all_subjects_ssm"] = all_subjects solr_doc["durst_subjects_ssim"] = durst_subjects solr_doc["lib_all_subjects_teim"] = solr_doc["lib_all_subjects_ssm"] solr_doc["all_text_teim"] += solr_doc["lib_all_subjects_teim"] solr_doc["lib_name_ssm"] = solr_doc["lib_name_sim"] solr_doc["lib_author_sim"] = names(:marcrelator, 'aut') solr_doc["lib_recipient_sim"] = names(:marcrelator, 'rcp') solr_doc["lib_format_sim"] = formats solr_doc["lib_shelf_sim"] = shelf_locators solr_doc['location_shelf_locator_ssm'] = solr_doc["lib_shelf_sim"] solr_doc["all_text_teim"] += solr_doc["lib_shelf_sim"] solr_doc['lib_sublocation_sim'] = sublocation solr_doc['lib_sublocation_ssm'] = solr_doc['lib_sublocation_sim'] solr_doc["all_text_teim"] += solr_doc['lib_sublocation_sim'] solr_doc["lib_date_textual_ssm"] = textual_dates solr_doc["lib_date_notes_ssm"] = date_notes solr_doc["lib_non_date_notes_ssm"] = non_date_notes solr_doc["lib_item_in_context_url_ssm"] = item_in_context_url solr_doc["lib_non_item_in_context_url_ssm"] = non_item_in_context_url solr_doc["lib_project_url_ssm"] = project_url solr_doc["origin_info_place_ssm"] = origin_info_place solr_doc["origin_info_place_for_display_ssm"] = origin_info_place_for_display repo_marc_code = repository_code unless repo_marc_code.nil? solr_doc["lib_repo_short_ssim"] = [translate_repo_marc_code(repo_marc_code, 'short')] solr_doc["lib_repo_long_sim"] = [translate_repo_marc_code(repo_marc_code, 'long')] solr_doc["lib_repo_full_ssim"] = [translate_repo_marc_code(repo_marc_code, 'full')] end solr_doc["lib_repo_text_ssm"] = repository_text project_titles = projects unless project_titles.nil? solr_doc["lib_project_short_ssim"] = [] solr_doc["lib_project_full_ssim"] = [] project_titles.each {|project_title| solr_doc["lib_project_short_ssim"] << translate_project_title(project_title, 'short') solr_doc["lib_project_full_ssim"] << translate_project_title(project_title, 'full') } solr_doc["lib_project_short_ssim"].uniq! solr_doc["lib_project_full_ssim"].uniq! end # Create convenient start and end date values based on one of the many possible originInfo/dateX elements. start_date, end_date = key_date_range start_year = nil end_year = nil if start_date.present? start_year = nil end_year = nil start_date = nil if start_date == 'uuuu' end_date = nil if end_date == 'uuuu' start_date = start_date.gsub('u', '0') unless start_date.nil? end_date = end_date.gsub('u', '0') unless end_date.nil? end_date = start_date if end_date.blank? start_date = end_date if start_date.blank? year_regex = /^(-?\d{1,4}).*/ unless start_date.blank? start_year_match = start_date.match(year_regex) if start_year_match && start_year_match.captures.length > 0 start_year = start_year_match.captures[0] start_year = zero_pad_year(start_year) solr_doc["lib_start_date_year_itsi"] = start_year.to_i # TrieInt version for searches end end unless end_date.blank? end_year_match = end_date.match(year_regex) if end_year_match && end_year_match.captures.length > 0 end_year = end_year_match.captures[0] end_year = zero_pad_year(end_year) solr_doc["lib_end_date_year_itsi"] = end_year.to_i # TrieInt version for searches end end solr_doc["lib_date_year_range_si"] = start_year + '-' + end_year if start_year && end_year solr_doc["lib_date_year_range_ss"] = solr_doc["lib_date_year_range_si"] # When no textual date is available, fall back to other date data (if available) if solr_doc["lib_date_textual_ssm"].blank? solr_doc["lib_date_textual_ssm"] = date_range_to_textual_date(start_year.to_i, end_year.to_i) end end # Geo data solr_doc["geo"] = coordinates ## Handle alternate form of language authority for language_language_term_text_ssim ## We already capture elements when authority="iso639-2b", but we want to additionally ## capture language elements when authority="iso639-2". solr_doc['language_language_term_text_ssim'] ||= [] solr_doc['language_language_term_text_ssim'] += languages_iso639_2_text solr_doc['language_language_term_code_ssim'] ||= [] solr_doc['language_language_term_code_ssim'] +=languages_iso639_2_code solr_doc.each do |k, v| if self.class.maps_field? k solr_doc[k] = self.class.map_value(k, v) end end solr_doc end |
#translate_project_title(project_title, type) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 192 def translate_project_title(project_title, type) normalized_project_title = ModsFieldable.normalize(project_title) if type == 'short' return translate_with_default(SHORT_PROJ, normalized_project_title, normalized_project_title) elsif type == 'full' return translate_with_default(FULL_PROJ, normalized_project_title, normalized_project_title) end return nil end |
#translate_repo_marc_code(code, type) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 178 def translate_repo_marc_code(code, type) #code = ModsFieldable.normalize(code) if type == 'short' return translate_with_default(SHORT_REPO, code, 'Non-Columbia Location') elsif type == 'long' return translate_with_default(LONG_REPO, code, 'Non-Columbia Location') elsif type == 'full' return translate_with_default(FULL_REPO, code, 'Non-Columbia Location') end return nil end |
#zero_pad_year(year) ⇒ Object
504 505 506 507 508 509 510 511 512 513 |
# File 'lib/cul_hydra/solrizer/mods_fieldable.rb', line 504 def zero_pad_year(year) year = year.to_s is_negative = year.start_with?('-') year_without_sign = (is_negative ? year[1, year.length]: year) if year_without_sign.length < 4 year_without_sign = year_without_sign.rjust(4, '0') end return (is_negative ? '-' : '') + year_without_sign end |