Module: Embulk::Guess::TimeFormatGuess
- Defined in:
- lib/embulk/guess/time_format_guess.rb
Defined Under Namespace
Modules: Parts, StandardPatterns Classes: GuessMatch, GuessPattern, RegexpMatch, RegexpPattern
Constant Summary collapse
- PATTERNS =
[ GuessPattern.new, RegexpPattern.new(StandardPatterns::RFC_822_1123, "%a, %d %b %Y %H:%M:%S %z"), RegexpPattern.new(StandardPatterns::RFC_850_1035, "%A, %d-%b-%y %H:%M:%S %z"), RegexpPattern.new(StandardPatterns::APACHE_CLF, "%d/%b/%Y %H:%M:%S %Z"), RegexpPattern.new(StandardPatterns::ANSI_C_ASCTIME, "$a %b %e %H:%M:%S %Y"), ]
Class Method Summary collapse
Class Method Details
.guess(texts) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/embulk/guess/time_format_guess.rb', line 315 def self.guess(texts) texts = Array(texts).select {|text| text != "" } matches = texts.map do |text| PATTERNS.map {|pattern| pattern.match(text) }.compact end.flatten if matches.empty? return nil elsif matches.size == 1 return matches[0].format else match_groups = matches.group_by {|match| match.mergeable_group } best_match_group = match_groups.sort_by {|group| group.size }.last[1] best_match = best_match_group.shift best_match_group.each {|m| best_match.merge!(m) } return best_match.format end end |