class Embulk::Guess::TimeFormatGuess::Rfc2822Pattern

Public Class Methods

new() click to toggle source
# File lib/embulk/guess/time_format_guess.rb, line 334
def initialize
  @regexp = /^(?<weekday>#{WEEKDAY_NAME_SHORT}, )?\d\d #{MONTH_NAME_SHORT} \d\d\d\d(?<time> \d\d:\d\d(?<second>:\d\d)? (?:(?<zone_off>#{ZONE_OFF})|(?<zone_abb>#{ZONE_ABB})))?$/
end

Public Instance Methods

match(text) click to toggle source
# File lib/embulk/guess/time_format_guess.rb, line 338
def match(text)
  if m = @regexp.match(text)
    format = ''
    format << "%a, " if m['weekday']
    format << "%d %b %Y"
    format << " %H:%M" if m['time']
    format << ":%S" if m['second']
    if m['zone_off']
      if m['zone_off'].include?(':')
        format << " %:z"
      else
        format << " %z"
      end
    elsif m['zone_abb']
      # don't use %Z: https://github.com/jruby/jruby/issues/3702
      format << " %z" if m['zone_abb']
    end
    SimpleMatch.new(format)
  else
    nil
  end
end