Module: MWDictionaryAPI::Parsable::ClassMethods

Defined in:
lib/mw_dictionary_api/parsable.rb

Instance Method Summary collapse

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, options)
  inherited_rules[attr_name][:block].call(data, options)
end

#inherited_rulesObject



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, **options, &block)
  rules[attr_name] = { attr_name: attr_name, options: 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

#rulesObject



10
11
12
# File 'lib/mw_dictionary_api/parsable.rb', line 10

def rules
  @rules ||= {}
end