class Ddr::Models::YearFacet
Constants
- BETWEEN
Between 1965 and 1968
- CENTURY
19uu => 19xx
- CIRCA
circa 1920, ca. 1920, c1920 => 1920
- DECADE
1920s, 1920s?, 192u, 192-, 192-?, 192? => 192x
- EARLIEST_YEAR
- END_DECADE
/194x, /194u => /1949
- LATEST_YEAR
- MONTH
2010/01 => 2010-01
- START_DECADE
193u/, 193x/ => 1930/
- VALID_YEARS
- VALUE_SEP
- YEAR_RANGE
1935-1940 => 1935/1940
Attributes
object[R]
Public Class Methods
call(object)
click to toggle source
# File lib/ddr/models/year_facet.rb, line 36 def self.call(object) new(object).call end
new(object)
click to toggle source
# File lib/ddr/models/year_facet.rb, line 42 def initialize(object) @object = object end
Public Instance Methods
call()
click to toggle source
# File lib/ddr/models/year_facet.rb, line 46 def call source_dates.each_with_object([]) do |date, facet_values| date.split(VALUE_SEP).each do |value| value.strip! edtf_date = convert_to_edtf(value) years = Array(edtf_years(edtf_date)) years.select! { |year| VALID_YEARS.include?(year) } facet_values.push(*years) end end end
Private Instance Methods
convert_to_edtf(value)
click to toggle source
# File lib/ddr/models/year_facet.rb, line 64 def convert_to_edtf(value) if m = BETWEEN.match(value) value.sub! m[1], "" # [Bb]etween value.sub! m[3], "/" # and end substitutions.reduce(value) { |memo, (regexp, repl)| memo.gsub(regexp, repl) } end
edtf_years(value)
click to toggle source
# File lib/ddr/models/year_facet.rb, line 84 def edtf_years(value) case parsed = EDTF.parse!(value) when Date, EDTF::Season parsed.year when EDTF::Set, EDTF::Interval, EDTF::Epoch parsed.map(&:year).uniq end rescue ArgumentError # EDTF cannot parse nil end
source_dates()
click to toggle source
# File lib/ddr/models/year_facet.rb, line 60 def source_dates object.desc_metadata.date end
substitutions()
click to toggle source
# File lib/ddr/models/year_facet.rb, line 72 def substitutions [ [ CIRCA, "" ], [ YEAR_RANGE, "/" ], [ DECADE, "x" ], [ MONTH, "-" ], [ START_DECADE, "0" ], [ END_DECADE, "9" ], [ CENTURY, "xx" ], ] end