Class: Embulk::Guess::TimeFormatGuess::Rfc2822Pattern
- Inherits:
-
Object
- Object
- Embulk::Guess::TimeFormatGuess::Rfc2822Pattern
- Includes:
- Parts
- Defined in:
- lib/embulk/guess/time_format_guess.rb
Constant Summary
Constants included from Parts
Parts::DAY, Parts::DAY_NODELIM, Parts::HOUR, Parts::HOUR_NODELIM, Parts::MINUTE, Parts::MINUTE_NODELIM, Parts::MONTH, Parts::MONTH_NAME_FULL, Parts::MONTH_NAME_SHORT, Parts::MONTH_NODELIM, Parts::WEEKDAY_NAME_FULL, Parts::WEEKDAY_NAME_SHORT, Parts::YEAR, Parts::ZONE_ABB, Parts::ZONE_OFF
Instance Method Summary collapse
-
#initialize ⇒ Rfc2822Pattern
constructor
A new instance of Rfc2822Pattern.
- #match(text) ⇒ Object
Constructor Details
#initialize ⇒ Rfc2822Pattern
Returns a new instance of Rfc2822Pattern.
334 335 336 |
# 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 |
Instance Method Details
#match(text) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# 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 |