Class: BobModel

Inherits:
Object
  • Object
show all
Defined in:
lib/dimibob/bob_model.rb

Overview

BobModel

Constant Summary collapse

DIMIBOB_API_URL =
'http://dimigo.in/pages/dimibob_getdata.php?d='.freeze

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ BobModel

Returns a new instance of BobModel.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dimibob/bob_model.rb', line 8

def initialize(date)
  meal_date = format('%04i%02i%02i', date.year, date.month, date.day)

  begin
    response = RestClient.get DIMIBOB_API_URL + meal_date
    @bob = JSON.parse(response.body)
  rescue
    @bob = {
      breakfast: 'Have No Data',
      lunch: 'Have No Data',
      dinner: 'Have No Data',
      snack: 'Have No Data'
    }
  end
  self
end

Instance Method Details

#breakfastObject



29
30
31
# File 'lib/dimibob/bob_model.rb', line 29

def breakfast
  @bob['breakfast'].split('/')
end

#dinnerObject



37
38
39
# File 'lib/dimibob/bob_model.rb', line 37

def dinner
  @bob['dinner'].split('/')
end

#lunchObject



33
34
35
# File 'lib/dimibob/bob_model.rb', line 33

def lunch
  @bob['lunch'].split('/')
end

#mealObject



25
26
27
# File 'lib/dimibob/bob_model.rb', line 25

def meal
  @bob
end

#snackObject



41
42
43
# File 'lib/dimibob/bob_model.rb', line 41

def snack
  @bob['snack'].split('/')
end