Class: Particle::Platform
Overview
Domain model for one Particle Platform from the /v1/build_targets endpoint
Constant Summary collapse
- IDS =
{ 0 => 'Core'.freeze, 6 => 'Photon'.freeze, 8 => 'P1'.freeze, 10 => 'Electron'.freeze, 31 => 'Raspberry Pi'.freeze, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client, attributes) ⇒ Platform
constructor
A new instance of Platform.
-
#name ⇒ Object
This avoids upstream magic from making .name a Symbol–keep it a string yo.
Methods inherited from Model
attribute_reader, #attributes, #get_attributes, #id, #inspect
Constructor Details
#initialize(client, attributes) ⇒ Platform
Returns a new instance of Platform.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/particle/platform.rb', line 13 def initialize(client, attributes) if attributes.is_a? String name = attributes attributes = { id: self.class.id_for_name(name), name: name } end if attributes.is_a? Integer id = attributes attributes = { id: id, name: self.class.name_for_id(id) } end super(client, attributes) end |
Class Method Details
.id_for_name(name) ⇒ Object
27 28 29 |
# File 'lib/particle/platform.rb', line 27 def self.id_for_name(name) IDS.invert[name] end |
.name_for_id(id) ⇒ Object
31 32 33 |
# File 'lib/particle/platform.rb', line 31 def self.name_for_id(id) IDS[id] end |
Instance Method Details
#name ⇒ Object
This avoids upstream magic from making .name a Symbol–keep it a string yo
38 39 40 |
# File 'lib/particle/platform.rb', line 38 def name @attributes[:name].to_s end |