Class: Datacash::Response::Base

Inherits:
Hash
  • Object
show all
Includes:
Hashie::Extensions::Coercion, Hashie::Extensions::MergeInitializer, Hashie::Extensions::MethodReader
Defined in:
lib/datacash/response/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/datacash/response/base.rb', line 8

def initialize(attributes = {})
  self.class.keys.each do |key, options|
    next unless options.has_key?(:from)

    from = options[:from].to_sym
    if attributes.has_key?(from)
      attributes[key] = attributes.delete(from)
    end
  end
  super(attributes)
end

Class Method Details

.key(key, options = {}) ⇒ Object



24
25
26
# File 'lib/datacash/response/base.rb', line 24

def self.key(key, options={})
  keys[key.to_sym] = options
end

.keysObject



20
21
22
# File 'lib/datacash/response/base.rb', line 20

def self.keys
  @keys ||= {}
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/datacash/response/base.rb', line 28

def success?
  self[:status].to_i == 1
end