Class: Building

Inherits:
Object
  • Object
show all
Defined in:
lib/building_rocksolid.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.



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

def initialize(input_options)
  # add attributes here as instance variables
  @name = input_options["name"]
  @address = input_options["address"] 
  @height = input_options["height"]
  @construction_date = input_options["construction_date"]
  @architect = input_options["architect"]
  @id = input_options["id"]
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#architectObject

Returns the value of attribute architect.



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

def architect
  @architect
end

#construction_dateObject

Returns the value of attribute construction_date.



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

def construction_date
  @construction_date
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allObject



17
18
19
20
21
22
23
# File 'lib/building_rocksolid.rb', line 17

def self.all
  response = HTTP.get("http://localhost:3000/api/buildings")
  buildings_details = response.parse
  buildings_details.map do |building_detail|
    Building.find(building_detail["id"])
  end
end

.create(building_details) ⇒ Object



25
26
27
28
29
# File 'lib/building_rocksolid.rb', line 25

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

.destroy(building_id) ⇒ Object



46
47
48
# File 'lib/building_rocksolid.rb', line 46

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

.find(input_id) ⇒ Object



31
32
33
34
35
36
# File 'lib/building_rocksolid.rb', line 31

def self.find(input_id)
  # write your logic for the method here
  response = HTTP.get("http://localhost:3000/api/buildings/#{input_id}")
  building_details = response.parse
  Building.new(building_details)
end

Instance Method Details

#update(client_params) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/building_rocksolid.rb', line 38

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

end