Class: TT::ActionFactory::Locale
- Inherits:
-
Object
- Object
- TT::ActionFactory::Locale
- Defined in:
- lib/t_t/action_factory.rb
Instance Method Summary collapse
- #compile(action) ⇒ Object
-
#initialize ⇒ Locale
constructor
A new instance of Locale.
- #knows_rule?(key) ⇒ Boolean
- #rule(key, &block) ⇒ Object
- #use_rule_for(key, *list) ⇒ Object
Constructor Details
#initialize ⇒ Locale
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., r_option.) end result end end |
#knows_rule?(key) ⇒ 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 |