Class: Building

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_options) ⇒ Building

Returns a new instance of Building.



8
9
10
11
12
13
14
15
# File 'lib/frozen_yogurt.rb', line 8

def initialize(input_options)
  @id = input_options["id"]
  @name = input_options["name"]
  @address  = input_options["address"]
  @height = input_options["height"]
  @construction_date = input_options["construction_date"]
  @architect = input_options["architect"]
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



7
8
9
# File 'lib/frozen_yogurt.rb', line 7

def address
  @address
end

#architectObject

Returns the value of attribute architect.



7
8
9
# File 'lib/frozen_yogurt.rb', line 7

def architect
  @architect
end

#construction_dateObject

Returns the value of attribute construction_date.



7
8
9
# File 'lib/frozen_yogurt.rb', line 7

def construction_date
  @construction_date
end

#heightObject

Returns the value of attribute height.



7
8
9
# File 'lib/frozen_yogurt.rb', line 7

def height
  @height
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/frozen_yogurt.rb', line 7

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/frozen_yogurt.rb', line 7

def name
  @name
end

Class Method Details

.allObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/frozen_yogurt.rb', line 23

def self.all
  response = HTTP.get("http://localhost:3000/api/buildings")
  building_array = response.parse

  all_building_objects = []
  building_array.each do |building| 
    all_building_objects << Building.new(building)
  end
  all_building_objects
end

.create(params_hash) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/frozen_yogurt.rb', line 34

def self.create(params_hash)
  response = HTTP.post(
                       "http://localhost:3000/api/buildings", 
                       form: params_hash
                      )
  new_building = response.parse
  Building.new(new_building)
end

.find(input_id) ⇒ Object



17
18
19
20
21
# File 'lib/frozen_yogurt.rb', line 17

def self.find(input_id)
  response = HTTP.get("http://localhost:3000/api/buildings/#{input_id}")
  building_hash = response.parse
  Building.new(building_hash)
end

Instance Method Details

#destroyObject



50
51
52
# File 'lib/frozen_yogurt.rb', line 50

def destroy
  response = HTTP.delete("http://localhost:3000/api/buildings/#{id}")
end

#update(input_hash) ⇒ Object



43
44
45
46
47
48
# File 'lib/frozen_yogurt.rb', line 43

def update(input_hash)
  response = HTTP.patch(
                        "http://localhost:3000/api/buildings/#{id}", 
                        form: input_hash
                        )
end