Class: Ampt::Song
- Inherits:
-
Object
- Object
- Ampt::Song
- Defined in:
- lib/ampt_api/acoustics.rb
Class Method Summary collapse
-
.json_create(o) ⇒ Object
Create from json.
Instance Method Summary collapse
-
#initialize(h) ⇒ Song
constructor
Takes a hash to set up the object.
-
#to_json(*a) ⇒ Object
Serialize to json.
Constructor Details
#initialize(h) ⇒ Song
Takes a hash to set up the object
180 181 182 183 184 185 186 187 |
# File 'lib/ampt_api/acoustics.rb', line 180 def initialize h h.each do |k,v| (class << self; self; end).instance_eval do attr_reader k end instance_variable_set '@'+k, v end end |
Class Method Details
.json_create(o) ⇒ Object
Create from json
165 166 167 |
# File 'lib/ampt_api/acoustics.rb', line 165 def self.json_create o new o['data'] if o['data'] end |
Instance Method Details
#to_json(*a) ⇒ Object
Serialize to json
169 170 171 172 173 174 175 176 177 |
# File 'lib/ampt_api/acoustics.rb', line 169 def to_json(*a) { 'json_class' => self.class.name, 'data' => [self.instance_variables.reduce({}) do |d,v| d[v[1..-1]] = self.instance_variable_get v d end] }.to_json(*a) end |