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



24
25
26
# File 'lib/mw_dictionary_api/parsable.rb', line 24

def apply_rule(attr_name, data, options)
  inherited_rules[attr_name][:block].call(data, options)
end

#inherited_rulesObject



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

#rulesObject



8
9
10
# File 'lib/mw_dictionary_api/parsable.rb', line 8

def rules
  @rules ||= {}
end