Module: MWDictionaryAPI::Parsable::ClassMethods
- Defined in:
- lib/mw_dictionary_api/parsable.rb
Instance Method Summary collapse
- #apply_rule(attr_name, data, options) ⇒ Object
- #inherited_rules ⇒ Object
- #rule(attr_name, **options, &block) ⇒ Object
- #rule_helpers(&block) ⇒ Object
- #rules ⇒ Object
Instance Method Details
#apply_rule(attr_name, data, options) ⇒ Object
24 25 26 |
# File 'lib/mw_dictionary_api/parsable.rb', line 24 def apply_rule(attr_name, data, ) inherited_rules[attr_name][:block].call(data, ) end |
#inherited_rules ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/mw_dictionary_api/parsable.rb', line 12 def inherited_rules if superclass.respond_to? :inherited_rules superclass.inherited_rules.merge(rules) else rules end end |
#rule(attr_name, **options, &block) ⇒ Object
20 21 22 |
# File 'lib/mw_dictionary_api/parsable.rb', line 20 def rule(attr_name, **, &block) rules[attr_name] = { attr_name: attr_name, options: , block: block } end |
#rule_helpers(&block) ⇒ Object
28 29 30 |
# File 'lib/mw_dictionary_api/parsable.rb', line 28 def rule_helpers(&block) instance_eval(&block) end |
#rules ⇒ Object
8 9 10 |
# File 'lib/mw_dictionary_api/parsable.rb', line 8 def rules @rules ||= {} end |