Class: Oura::Model::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/oura/model/base.rb

Overview

Oura::Mode::Base is base class for Model.

Direct Known Subclasses

Activity, Readiness, SleepPeriod, UserInformation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Returns a new instance of Base.



26
27
28
# File 'lib/oura/model/base.rb', line 26

def initialize(attrs = {})
  @attrs = attrs
end

Instance Attribute Details

#attrsObject (readonly) Also known as: to_hash

Returns the value of attribute attrs.



36
37
38
# File 'lib/oura/model/base.rb', line 36

def attrs
  @attrs
end

Class Method Details

.attr_reader(*attrs) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/oura/model/base.rb', line 7

def self.attr_reader(*attrs)
  mod = Module.new do
    attrs.each do |attribute|
      define_method attribute do
        @attrs[attribute.to_sym]
      end
      define_method :"#{attribute}?" do
        !!@attrs[attribute.to_sym]
      end
    end
  end
  const_set(:Attributes, mod) unless defined? Attributes
  include mod
end

.object_from_response(response = {}) ⇒ Object



22
23
24
# File 'lib/oura/model/base.rb', line 22

def self.object_from_response(response = {})
  new(response[:body])
end

Instance Method Details

#[](method) ⇒ Object



30
31
32
33
34
# File 'lib/oura/model/base.rb', line 30

def [](method)
  send(method.to_sym)
rescue NoMethodError => e
  puts e.inspect
end

#update(attrs) ⇒ Object



39
40
41
42
# File 'lib/oura/model/base.rb', line 39

def update(attrs)
  @attrs.update(attrs)
  self
end