Class: Grubber::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/grubber/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
# File 'lib/grubber/config.rb', line 8

def initialize(opts={})
  @store = Grubber::Store.load[:grubber]

  location = store[:location]
  @lat = location[:lat]
  @lng = location[:lng]
  
  @credentials = store[:credentials]
  self
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



6
7
8
# File 'lib/grubber/config.rb', line 6

def credentials
  @credentials
end

#latObject

Returns the value of attribute lat.



6
7
8
# File 'lib/grubber/config.rb', line 6

def lat
  @lat
end

#lngObject

Returns the value of attribute lng.



6
7
8
# File 'lib/grubber/config.rb', line 6

def lng
  @lng
end

#storeObject

Returns the value of attribute store.



6
7
8
# File 'lib/grubber/config.rb', line 6

def store
  @store
end

Class Method Details

.loadObject



19
20
21
# File 'lib/grubber/config.rb', line 19

def self.load
  new
end

.update_auth(ckey, csec, tkey, tsec) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/grubber/config.rb', line 43

def self.update_auth(ckey, csec, tkey, tsec)
  [ckey, csec, tkey, tsec].each do |k|
    return nil if k.nil? || k == ''
  end

  Grubber::Store.update({
    credentials: {
      consumer_key: ckey,
      consumer_secret: csec,
      token_key: tkey,
      token_secret: tsec
    }
  })
end

.update_locationObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/grubber/config.rb', line 58

def self.update_location
  lat, lng = *Lost.current_position
  Grubber::Store.update({
    location: {
      lat: lat,
      lng: lng
    }
  })
  return [lat, lng]
end

Instance Method Details

#coordinatesObject



23
24
25
# File 'lib/grubber/config.rb', line 23

def coordinates
  [lat, lng]
end

#has_auth?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/grubber/config.rb', line 27

def has_auth?
  !self.credentials.nil?
end