Class: RippleRest::RestObject
- Inherits:
-
Object
- Object
- RippleRest::RestObject
- Defined in:
- lib/ripple-rest/rest-object.rb
Direct Known Subclasses
AccountSettings, Amount, Balance, Notification, Order, Payment, Trustline
Instance Method Summary collapse
-
#initialize(data = nil) ⇒ RestObject
constructor
A new instance of RestObject.
-
#to_hash ⇒ Hash
Convert to a hash.
Constructor Details
#initialize(data = nil) ⇒ RestObject
Returns a new instance of RestObject.
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ripple-rest/rest-object.rb', line 131 def initialize data = nil data.each do |key, value| if @@properties[self.class][key.to_sym] self.instance_variable_set :"@#{key}", RestTypeHelper.convert_from(@@properties[self.class][key.to_sym], value) else warn "Cannot found field `#{key}' in RippleRestObject #{self.class}. The value will leave as-is. However, this will not be serialized to JSON." self.instance_variable_set :"@#{key}", value end end if data end |
Instance Method Details
#to_hash ⇒ Hash
Convert to a hash
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ripple-rest/rest-object.rb', line 144 def to_hash result = {} @@properties[self.class].each do |key, type| value = self.instance_variable_get(:"@#{key}") if @@required[self.class][key] && value == nil raise ArgumentError.new("Field `#{key}' is required in RippleRestObject #{self.class}.") end result[key] = RestTypeHelper.convert_to(type, value) if value != nil end result end |