Class: TT::ActionFactory::Locale

Inherits:
Object
  • Object
show all
Defined in:
lib/t_t/action_factory.rb

Instance Method Summary collapse

Constructor Details

#initializeLocale

Returns a new instance of Locale.



13
14
15
16
# File 'lib/t_t/action_factory.rb', line 13

def initialize
  @rules = {}
  @list  = {}
end

Instance Method Details

#compile(action) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/t_t/action_factory.rb', line 31

def compile(action)
  action.rules.inject(base: action.base) do |result, a_option|
    rule = @rules.fetch(a_option.key)

    @list.fetch(a_option.key).each do |r_option|
      base = result.fetch(r_option.key, action.base)
      result[r_option.key] = rule.call(base, a_option.meta, r_option.meta)
    end

    result
  end
end

#knows_rule?(key) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/t_t/action_factory.rb', line 27

def knows_rule?(key)
  @rules.has_key?(key)
end

#rule(key, &block) ⇒ Object



18
19
20
21
# File 'lib/t_t/action_factory.rb', line 18

def rule(key, &block)
  @rules[key] = block
  @list[key]  = []
end

#use_rule_for(key, *list) ⇒ Object



23
24
25
# File 'lib/t_t/action_factory.rb', line 23

def use_rule_for(key, *list)
  @list[key].concat(Option.parse(list))
end