class ApacheCrunch::TimeDerivationRule

Derivation rule for elements derived from TimeToken

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

derive(name, source_value) click to toggle source
# 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() click to toggle source
# File lib/derivation.rb, line 33
def source_name
    :time
end
target_names() click to toggle source
# File lib/derivation.rb, line 37
def target_names
    [:year, :month, :day, :hour, :minute, :second]
end