Class: Embulk::Guess::TimeFormatGuess::GuessMatch
- Inherits:
-
Object
- Object
- Embulk::Guess::TimeFormatGuess::GuessMatch
- Defined in:
- lib/embulk/guess/time_format_guess.rb
Instance Attribute Summary collapse
-
#part_options ⇒ Object
readonly
Returns the value of attribute part_options.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #array_sequence_find(array, seq) ⇒ Object
- #format ⇒ Object
-
#initialize(delimiters, parts, part_options) ⇒ GuessMatch
constructor
A new instance of GuessMatch.
- #merge!(another_in_group) ⇒ Object
- #mergeable_group ⇒ Object
Constructor Details
#initialize(delimiters, parts, part_options) ⇒ GuessMatch
Returns a new instance of GuessMatch.
25 26 27 28 29 |
# File 'lib/embulk/guess/time_format_guess.rb', line 25 def initialize(delimiters, parts, ) @delimiters = delimiters @parts = parts @part_options = end |
Instance Attribute Details
#part_options ⇒ Object (readonly)
Returns the value of attribute part_options.
136 137 138 |
# File 'lib/embulk/guess/time_format_guess.rb', line 136 def @part_options end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
135 136 137 |
# File 'lib/embulk/guess/time_format_guess.rb', line 135 def parts @parts end |
Instance Method Details
#array_sequence_find(array, seq) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/embulk/guess/time_format_guess.rb', line 159 def array_sequence_find(array, seq) (array.size - seq.size + 1).times {|i| return i if array[i, seq.size] == seq } return nil end |
#format ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/embulk/guess/time_format_guess.rb', line 31 def format format = '' @parts.size.times do |i| format << @delimiters[i-1] if i != 0 option = @part_options[i] case @parts[i] when :year format << '%Y' when :month case option when :zero format << '%m' when :blank #format << '%_m' # not supported format << '%m' when :none #format << '%-m' # not supported format << '%m' else format << '%m' end when :day case option when :zero format << '%d' when :blank format << '%e' when :none format << '%d' # not supported else format << '%d' end when :hour case option when :zero format << '%H' when :blank format << '%k' when :none format << '%k' # not supported else format << '%H' end when :minute # heading options are not supported format << '%M' when :second # heading options are not supported format << '%S' when :frac if option <= 3 format << '%L' #elsif option <= 6 # format << '%6N' #elsif option <= 6 # format << '%6N' #elsif option <= 9 # format << '%9N' #elsif option <= 12 # format << '%12N' #elsif option <= 15 # format << '%15N' #elsif option <= 18 # format << '%18N' #elsif option <= 21 # format << '%21N' #elsif option <= 24 # format << '%24N' else format << '%N' end when :zone_off format << '%z' when :zone_abb format << '%Z' else raise "Unknown part: #{@parts[i]}" end end return format end |
#merge!(another_in_group) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/embulk/guess/time_format_guess.rb', line 138 def merge!(another_in_group) = another_in_group. @part_options.size.times do |i| @part_options[i] ||= [i] if @part_options[i] == nil [i] elsif [i] == nil @part_options[i] else [@part_options[i], [i]].sort.last end end # if DMY matches, MDY is likely false match of DMY. dmy = array_sequence_find(another_in_group.parts, [:day, :month, :year]) mdy = array_sequence_find(@parts, [:month, :day, :year]) if mdy && dmy @parts[mdy, 3] = [:day, :month, :year] end end |
#mergeable_group ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/embulk/guess/time_format_guess.rb', line 124 def mergeable_group # MDY is mergible with DMY if i = array_sequence_find(@parts, [:day, :month, :year]) ps = @parts.dup ps[i, 3] = [:month, :day, :year] [@delimiters, ps] else [@delimiters, @parts] end end |