Class: Renstar::APIClient::APIObject
- Inherits:
-
Object
- Object
- Renstar::APIClient::APIObject
- Defined in:
- lib/renstar/api_client/api_object.rb
Overview
Base API Object class from which other objects inherit
Instance Method Summary collapse
- #human_readable(type) ⇒ Object
-
#initialize(raw_hash) ⇒ APIObject
constructor
A new instance of APIObject.
- #to_h ⇒ Object
Constructor Details
#initialize(raw_hash) ⇒ APIObject
Returns a new instance of APIObject.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/renstar/api_client/api_object.rb', line 7 def initialize(raw_hash) @raw_hash = raw_hash raw_hash.each do |key, value| value = Time.at(value) if key == 'ts' instance_variable_set("@#{key}", value) define_singleton_method(key) do instance_variable_get("@#{key}") end end end |
Instance Method Details
#human_readable(type) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/renstar/api_client/api_object.rb', line 23 def human_readable(type) @raw_hash.map do |key, value| description = APIClient.key_to_description(type, key) formatted_value = APIClient.value_to_formatted(type, key, value) format("%-35<description>s %<formatted_value>s\n", { description: description, formatted_value: formatted_value }) end.join end |
#to_h ⇒ Object
19 20 21 |
# File 'lib/renstar/api_client/api_object.rb', line 19 def to_h @raw_hash end |