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
26 27 28 |
# File 'lib/mw_dictionary_api/parsable.rb', line 26 def apply_rule(attr_name, data, ) inherited_rules[attr_name][:block].call(data, ) end |
#inherited_rules ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/mw_dictionary_api/parsable.rb', line 14 def inherited_rules if superclass.respond_to? :inherited_rules superclass.inherited_rules.merge(rules) else rules end end |
#rule(attr_name, **options, &block) ⇒ Object
22 23 24 |
# File 'lib/mw_dictionary_api/parsable.rb', line 22 def rule(attr_name, **, &block) rules[attr_name] = { attr_name: attr_name, options: , block: block } end |
#rule_helpers(&block) ⇒ Object
30 31 32 |
# File 'lib/mw_dictionary_api/parsable.rb', line 30 def rule_helpers(&block) instance_eval(&block) end |
#rules ⇒ Object
10 11 12 |
# File 'lib/mw_dictionary_api/parsable.rb', line 10 def rules @rules ||= {} end |