Class: Withings::Api::TypeBase

Inherits:
Object
  • Object
show all
Defined in:
lib/withings-api/types.rb

Constant Summary collapse

@@lookup_by_id =

Lookup helpers for static types

{}
@@lookup_by_name =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, description) ⇒ TypeBase

Returns a new instance of TypeBase.



7
8
9
10
11
# File 'lib/withings-api/types.rb', line 7

def initialize(id, name, description)
  self.id = id
  self.name = name
  self.description = description
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/withings-api/types.rb', line 5

def description
  @description
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/withings-api/types.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/withings-api/types.rb', line 5

def name
  @name
end

Class Method Details

.lookup(key) ⇒ Object



32
33
34
35
36
37
# File 'lib/withings-api/types.rb', line 32

def self.lookup(key)
  lookup_by_id = @@lookup_by_id[self] ||= {}
  lookup_by_name = @@lookup_by_name[self] ||= {}

  lookup_by_id[key] || lookup_by_name[key]
end

.register(instance) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/withings-api/types.rb', line 24

def self.register(instance)
  lookup_by_id = @@lookup_by_id[self] ||= {}
  lookup_by_name = @@lookup_by_name[self] ||= {}

  lookup_by_id[instance.id] = instance
  lookup_by_name[instance.name] = instance
end

Instance Method Details

#inspectObject



13
14
15
# File 'lib/withings-api/types.rb', line 13

def inspect
  self.description
end