Class: ExchangeRatesAPI::PayloadWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/exchangeratesapi/payload_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ PayloadWrapper

Returns a new instance of PayloadWrapper.



7
8
9
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 7

def initialize(data)
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 55

def method_missing(method_name, *args, &block)
  if data.respond_to?(method_name)
    data.send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 5

def data
  @data
end

Instance Method Details

#baseObject



15
16
17
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 15

def base
  data["base"]
end

#dateObject



19
20
21
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 19

def date
  data["date"]
end

#error?Boolean

Returns:



35
36
37
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 35

def error?
  !data["error"].nil?
end

#error_infoObject



39
40
41
42
43
44
45
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 39

def error_info
  return nil unless error?
  {
    "code" => data["error"]["code"],
    "message" => data["error"]["info"]
  }
end

#historical?Boolean

Returns:



31
32
33
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 31

def historical?
  data["historical"] == true
end

#ratesObject



23
24
25
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 23

def rates
  data["rates"] || {}
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:



63
64
65
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 63

def respond_to_missing?(method_name, include_private = false)
  data.respond_to?(method_name) || super
end

#success?Boolean

Returns:



11
12
13
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 11

def success?
  data["success"] == true
end

#timestampObject



27
28
29
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 27

def timestamp
  data["timestamp"]
end

#to_hObject



47
48
49
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 47

def to_h
  data
end

#to_jsonObject



51
52
53
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 51

def to_json
  data.to_json
end