Sha256: 3ac9d5ea50619857cdd5b9de2babe745c80fb7267f230804d469e8ac41e88768

Contents?: true

Size: 631 Bytes

Versions: 3

Compression:

Stored size: 631 Bytes

Contents

require 'timezone/parser/rule'
require 'time'

module Timezone::Parser::Rule
  def self.on(*args) ; On.new(*args) ; end

  class On
    @@rules = []

    # Given a Rule `on` field, parse the appropriate day and month.
    def self.parse(day, month, year)
      @@rules.each do |rule|
        if match = day.match(rule.expression)
          return rule.block.call(match, day, month, year)
        end
      end

      [month, day]
    end

    attr_reader :expression, :block

    def initialize(name, expression, block)
      @name = name
      @expression = expression
      @block = block
      @@rules << self
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
timezone-0.3.2 lib/timezone/parser/rule/on.rb
timezone-0.3.1 lib/timezone/parser/rule/on.rb
timezone-0.3.0 lib/timezone/parser/rule/on.rb