Sha256: 2f050a129b6ca3bf0900771341f4a03b2050c6dea5f6eaf47acef1a77fff4c9f

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'date'

module Identification
  module Parser
    # Represents a document parser.
    # This class carries base methods that are required to process all documents.
    #
    # @private 
    # @abstract Subclass and implement a {#parse} method for the specific document type.
    class Parser
      def self.yymmdd_to_ruby_date(input_date)
        # Only putting the last 2 digits of a date has the flaw of not knowing which century.
        # So I use the current year as a cut off.
        # Sorry to those over 100! :-(
        current_year_yy = (Date.today.strftime('%Y'))[2..4]
        input_year_yy = input_date[0..1]
        input_month = input_date[2..3]
        input_day = input_date[4..5]

        begin
          return Date.parse(input_day + '-' + input_month + '-' + '19' + input_year_yy) if input_year_yy >= current_year_yy
        rescue
          return false
        end

        begin
          return Date.parse(input_day + '-' + input_month + '-' + '20' + input_year_yy)
        rescue
          return false
        end
      end

      private_class_method :yymmdd_to_ruby_date
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
identification-0.1.0 lib/identification/parser/parser.rb