Class: ExchangeRatesAPI::PayloadWrapper
- Inherits:
-
Object
- Object
- ExchangeRatesAPI::PayloadWrapper
show all
- Defined in:
- lib/exchangeratesapi/payload_wrapper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
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
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 5
def data
@data
end
|
Instance Method Details
#base ⇒ Object
15
16
17
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 15
def base
data["base"]
end
|
#date ⇒ Object
19
20
21
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 19
def date
data["date"]
end
|
#error? ⇒ Boolean
35
36
37
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 35
def error?
!data["error"].nil?
end
|
#error_info ⇒ Object
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
31
32
33
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 31
def historical?
data["historical"] == true
end
|
#rates ⇒ Object
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
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
11
12
13
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 11
def success?
data["success"] == true
end
|
#timestamp ⇒ Object
27
28
29
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 27
def timestamp
data["timestamp"]
end
|
#to_h ⇒ Object
47
48
49
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 47
def to_h
data
end
|
#to_json ⇒ Object
51
52
53
|
# File 'lib/exchangeratesapi/payload_wrapper.rb', line 51
def to_json
data.to_json
end
|