module MWDictionaryAPI::Parsable

Public Class Methods

included(base) click to toggle source
# File lib/mw_dictionary_api/parsable.rb, line 5
def self.included(base)
  base.extend(ClassMethods)
end
new(**options) click to toggle source
# File lib/mw_dictionary_api/parsable.rb, line 35
def initialize(**options)
  @options = options
end

Public Instance Methods

parse(data) click to toggle source
# 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