Sha256: 6d44b0f154ab38e543134dbf13d33d4bf5cac82948ddfe0971c5f55482b4bc02

Contents?: true

Size: 565 Bytes

Versions: 2

Compression:

Stored size: 565 Bytes

Contents

module KindleManager
  module Parsers
    module Common
      extend ActiveSupport::Concern

      included do
        attr_accessor :fetched_at
      end

      def parse_date(date_text)
        begin
          Date.parse(date_text)
        rescue ArgumentError => e
          m = date_text.match(/\A(?<year>\d{4})年(?<month>\d{1,2})月(?<day>\d{1,2})日\z/)
          m = date_text.match(/(?<month>\d{1,2})月\D+(?<day>\d{1,2}),\D+(?<year>\d{4})/) if m.nil?
          Date.new(m[:year].to_i, m[:month].to_i, m[:day].to_i)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kindle_manager-0.6.0 lib/kindle_manager/parsers/common.rb
kindle_manager-0.5.0 lib/kindle_manager/parsers/common.rb