Sha256: eff652623f3fe99cd4e0e168d83f24cf306c59c779772bf162cb1fe4ba038e50

Contents?: true

Size: 926 Bytes

Versions: 18

Compression:

Stored size: 926 Bytes

Contents

module Krikri::Enrichments
  ##
  # Normalizes date strings to EDTF or Date objects.
  #
  # Attempts to convert a string value to a Date object:
  #
  #   - Parses EDTF values, returns an appropriate EDTF object if
  #     a match is found; then...
  #   - Parses values in %m*%d*%Y format and returns a Date object if
  #     appropriate.
  #   - Parses values that match any of Date#parse's supported formats.
  #
  # If the value is not a `String` or is parsed as invalid by all
  # parsers, the original value is returned unaltered.
  #
  # @see Date#parse
  # @see https://github.com/inukshuk/edtf-ruby/blob/master/README.md Ruby EDTF
  # @see http://www.loc.gov/standards/datetime/pre-submission.html EDTF Draft
  class ParseDate
    include Krikri::FieldEnrichment

    def enrich_value(value)
      return value unless value.is_a? String
      Krikri::Util::ExtendedDateParser.parse(value) || value
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
krikri-0.6.0 lib/krikri/enrichments/parse_date.rb
krikri-0.5.7 lib/krikri/enrichments/parse_date.rb
krikri-0.5.6 lib/krikri/enrichments/parse_date.rb
krikri-0.5.5 lib/krikri/enrichments/parse_date.rb
krikri-0.5.4 lib/krikri/enrichments/parse_date.rb
krikri-0.5.3 lib/krikri/enrichments/parse_date.rb
krikri-0.5.2 lib/krikri/enrichments/parse_date.rb
krikri-0.5.1 lib/krikri/enrichments/parse_date.rb
krikri-0.5.0 lib/krikri/enrichments/parse_date.rb
krikri-0.4.0 lib/krikri/enrichments/parse_date.rb
krikri-0.3.3 lib/krikri/enrichments/parse_date.rb
krikri-0.3.2 lib/krikri/enrichments/parse_date.rb
krikri-0.3.1 lib/krikri/enrichments/parse_date.rb
krikri-0.2.1 lib/krikri/enrichments/parse_date.rb
krikri-0.2.0 lib/krikri/enrichments/parse_date.rb
krikri-0.1.3 lib/krikri/enrichments/parse_date.rb
krikri-0.1.2 lib/krikri/enrichments/parse_date.rb
krikri-0.1.1 lib/krikri/enrichments/parse_date.rb