Class: ApacheCrunch::TimeDerivationRule
- Inherits:
-
DerivationRule
- Object
- DerivationRule
- ApacheCrunch::TimeDerivationRule
- Defined in:
- lib/derivation.rb
Overview
Derivation rule for elements derived from TimeToken
Instance Method Summary collapse
- #derive(name, source_value) ⇒ Object
-
#initialize ⇒ TimeDerivationRule
constructor
A new instance of TimeDerivationRule.
- #source_name ⇒ Object
- #target_names ⇒ Object
Constructor Details
#initialize ⇒ TimeDerivationRule
Returns a new instance of TimeDerivationRule.
26 27 28 29 30 31 |
# File 'lib/derivation.rb', line 26 def initialize @_derivation_regex = nil @_month_map = {"Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12} end |
Instance Method Details
#derive(name, source_value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/derivation.rb', line 41 def derive(name, source_value) if @_derivation_regex.nil? @_derivation_regex = Regexp.compile(%q!^\[(\d\d)/([A-Za-z]{3})/(\d\d\d\d):(\d\d):(\d\d):(\d\d)!) end hsh = {} if source_value =~ @_derivation_regex hsh[:year] = $3.to_i hsh[:month] = @_month_map[$2] hsh[:day] = $1.to_i hsh[:hour] = $4.to_i hsh[:minute] = $5.to_i hsh[:second] = $6.to_i end hsh[name] end |
#source_name ⇒ Object
33 34 35 |
# File 'lib/derivation.rb', line 33 def source_name :time end |
#target_names ⇒ Object
37 38 39 |
# File 'lib/derivation.rb', line 37 def target_names [:year, :month, :day, :hour, :minute, :second] end |