Class: Ddr::Models::YearFacet
- Inherits:
-
Object
- Object
- Ddr::Models::YearFacet
- Defined in:
- lib/ddr/models/year_facet.rb
Constant Summary collapse
- EARLIEST_YEAR =
1000
- LATEST_YEAR =
Date.today.year + 100
- VALID_YEARS =
(EARLIEST_YEAR..LATEST_YEAR)
- VALUE_SEP =
/;/
- BETWEEN =
Between 1965 and 1968
Regexp.new '\A([Bb]etween\s+)(\d{4})(\s+and\s+)(\d{4})\??\z'
- CIRCA =
circa 1920, ca. 1920, c1920 => 1920
Regexp.new '\b(circa\s+|ca?\.\s*|c(?=\d{4}[^\d]*))'
- YEAR_RANGE =
1935-1940 => 1935/1940
Regexp.new '(?<=\d{4})-(?=\d{4})'
- DECADE =
1920s, 1920s?, 192u, 192-, 192-?, 192? => 192x
Regexp.new '(?<=\A\d{3})(-\??|0s\??|u|\?)\z'
- MONTH =
2010/01 => 2010-01
Regexp.new '(?<=\A\d{4})\/(?=\d{2}\z)'
- START_DECADE =
193u/, 193x/ => 1930/
Regexp.new '(?<=\d{3})[uxX](?=\/)'
- END_DECADE =
/194x, /194u => /1949
Regexp.new '(?<=\/\d{3})[uxX]'
- CENTURY =
19uu => 19xx
Regexp.new '(?<=\A\d{2})uu(?=\z)'
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(object) ⇒ YearFacet
constructor
A new instance of YearFacet.
Constructor Details
#initialize(object) ⇒ YearFacet
Returns a new instance of YearFacet.
42 43 44 |
# File 'lib/ddr/models/year_facet.rb', line 42 def initialize(object) @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
40 41 42 |
# File 'lib/ddr/models/year_facet.rb', line 40 def object @object end |
Class Method Details
.call(object) ⇒ Object
36 37 38 |
# File 'lib/ddr/models/year_facet.rb', line 36 def self.call(object) new(object).call end |
Instance Method Details
#call ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# 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 |