Module: MWDictionaryAPI::Parsable

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/mw_dictionary_api/parsable.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize(**options) ⇒ Object



35
36
37
# File 'lib/mw_dictionary_api/parsable.rb', line 35

def initialize(**options)
  @options = options
end

#parse(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mw_dictionary_api/parsable.rb', line 39

def parse(data)
  attributes = {}

  self.class.inherited_rules.each do |attr_name, rule|
    unless rule[:options][:hidden]
      options = @options.merge(rule[:options])
      attributes[attr_name] = rule[:block].call(data, options)
    end
  end
  attributes
end