Class: MtgApi::RequestEntity

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mtg_api/request_entity.rb

Overview

represents an entity being returned from the API

Direct Known Subclasses

Card, Set

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ RequestEntity

build a card set from a set of attributes



7
8
9
10
11
# File 'lib/mtg_api/request_entity.rb', line 7

def initialize(attributes = {})
  attributes.each do |key, value|
    send(:"#{key}=", value) if respond_to?(:"#{key}=")
  end
end

Class Attribute Details

.configObject

the stored Config instance for this class



20
21
22
# File 'lib/mtg_api/request_entity.rb', line 20

def config
  @config
end

Class Method Details

.configure(&block) ⇒ Object

build a config and evaluate the block inside of it



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mtg_api/request_entity.rb', line 27

def configure(&block)
  self.config = Config.new(self)
  config.instance_eval(&block)

  attr_accessor *config.accessors
  attr_reader *config.setters.keys

  config.setters.each do |name, definition|
    define_method(:"#{name}=", definition)
  end
end

Instance Method Details

#attributesObject

the attributes of this request entity



14
15
16
# File 'lib/mtg_api/request_entity.rb', line 14

def attributes
  self.class.config.full_config.map { |attribute| [attribute, send(attribute)] }.to_h
end