Module: MWDictionaryAPI::Parsable

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/mw_dictionary_api/parsable.rb', line 3

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

Instance Method Details

#initialize(**options) ⇒ Object



33
34
35
# File 'lib/mw_dictionary_api/parsable.rb', line 33

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

#parse(data) ⇒ Object



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

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