Class: WebPay::Entity
- Inherits:
-
Object
- Object
- WebPay::Entity
- Defined in:
- lib/webpay/data_types.rb
Direct Known Subclasses
AccountResponse, BasicListRequest, CardRequest, CardResponse, ChargeFeeResponse, ChargeIdRequest, ChargeListRequest, ChargeRequestCreate, ChargeRequestRefund, ChargeRequestWithAmount, ChargeResponse, ChargeResponseList, CreatedRange, CustomerIdRequest, CustomerRequestCreate, CustomerRequestUpdate, CustomerResponse, CustomerResponseList, DeletedResponse, EmptyRequest, ErrorBody, ErrorData, EventData, EventIdRequest, EventListRequest, EventResponse, EventResponseList, RecursionIdRequest, RecursionListRequest, RecursionRequestCreate, RecursionRequestResume, RecursionResponse, RecursionResponseList, ShopIdRequest, ShopRequestAlterStatus, ShopRequestCreate, ShopRequestUpdate, ShopResponse, ShopResponseList, TokenIdRequest, TokenRequestCreate, TokenResponse
Instance Method Summary collapse
-
#normalize_hash(hash) ⇒ Object
Remove nil values and stringify keys.
-
#to_h ⇒ Hash
(also: #to_hash)
Convert attributes and its children to pure-Ruby hash.
-
#to_s ⇒ Object
(also: #inspect)
Pretty print object’s data.
Instance Method Details
#normalize_hash(hash) ⇒ Object
Remove nil values and stringify keys
4 5 6 |
# File 'lib/webpay/data_types.rb', line 4 def normalize_hash(hash) hash.each_with_object({}) { |kv, obj| k,v = kv; obj[k.to_s] = v unless v == nil } end |
#to_h ⇒ Hash Also known as: to_hash
Convert attributes and its children to pure-Ruby hash
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/webpay/data_types.rb', line 10 def to_h @attributes.each_with_object({}) do |kv, obj| k, v = kv next if v == nil obj[k] = case v when Entity v.to_h when Array v.map { |elem| elem.respond_to?(:to_h) ? elem.to_h : elem } else v end end end |
#to_s ⇒ Object Also known as: inspect
Pretty print object’s data
29 30 31 32 33 34 35 |
# File 'lib/webpay/data_types.rb', line 29 def to_s rendered = "#<#{self.class}\n" self.class.fields.each do |k| rendered << " #{k}: " << @attributes[k].inspect.gsub(/(\r?\n)/, '\1 ') << "\n" end rendered << ">" end |