Class: GarminConnect::Base::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/garmin_connect/base.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/garmin_connect/base.rb', line 107

def method_missing(method, *args)
  if args.size == 1 && method.to_s =~ /(.*)=$/ # ripped from hashie

    return self[$1.to_s] = args.first
  end
  obj = self[method.to_s]
  case obj
  when Base::Hash, Base::Array
    obj
  when Hash, Array
    self[method.to_s] = Base.generate(obj)
  when nil
    super(method, *args)
  else
    obj
  end
end

Instance Method Details

#displayObject



104
105
106
# File 'lib/garmin_connect/base.rb', line 104

def display
  self.fetch('display') { super }
end

#keyObject

garmin data uses ‘display’ and ‘key’ as keys. this is why we can’t use Hashie as well



101
102
103
# File 'lib/garmin_connect/base.rb', line 101

def key
  self.fetch('key') { super }
end