Sha256: edf403c6e117bfa64d6d23911becd2fc36660c4ddae8f00c59c8cd69a611202a

Contents?: true

Size: 1010 Bytes

Versions: 22

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true
module Mail::Parsers
  class DateTimeParser
    include Mail::Utilities

    def parse(s)
      raise Mail::Field::ParseError.new(Mail::DateTimeElement, s, "nil is an invalid DateTime") if s.nil?

      date_time = DateTimeStruct.new([])

      actions, error = Ragel.parse(:date_time, s)
      if error
        raise Mail::Field::ParseError.new(Mail::DateTimeElement, s, error)
      end

      date_s = time_s = nil
      actions.each_slice(2) do |action_id, p|
        action = Mail::Parsers::Ragel::ACTIONS[action_id]
        case action

        # Date
        when :date_s then date_s = p
        when :date_e
          date_time.date_string = s[date_s..(p-1)]

        # Time
        when :time_s then time_s = p
        when :time_e
          date_time.time_string = s[time_s..(p-1)]

        else
          raise Mail::Field::ParseError.new(Mail::DateTimeElement, s, "Failed to process unknown action: #{action}")
        end
      end

      date_time
    end
  end
end

Version data entries

22 entries across 20 versions & 6 rubygems

Version Path
tdiary-5.0.6 vendor/bundle/gems/mail-2.6.6/lib/mail/parsers/date_time_parser.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.6/lib/mail/parsers/date_time_parser.rb
mail-2.6.6 lib/mail/parsers/date_time_parser.rb
mail-2.6.6.rc1 lib/mail/parsers/date_time_parser.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/mail-2.6.5/lib/mail/parsers/date_time_parser.rb
mail-2.6.5 lib/mail/parsers/date_time_parser.rb
mail-2.6.5.rc1 lib/mail/parsers/date_time_parser.rb
tdiary-5.0.4 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
abaci-0.3.0 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
tdiary-5.0.2 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb
tdiary-5.0.1 vendor/bundle/gems/mail-2.6.4/lib/mail/parsers/date_time_parser.rb