Class: Building

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



5
6
7
8
9
10
11
12
# File 'lib/building.rb', line 5

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

Instance Attribute Details

#addressObject

Returns the value of attribute address.



3
4
5
# File 'lib/building.rb', line 3

def address
  @address
end

#architectObject

Returns the value of attribute architect.



3
4
5
# File 'lib/building.rb', line 3

def architect
  @architect
end

#construction_dateObject

Returns the value of attribute construction_date.



3
4
5
# File 'lib/building.rb', line 3

def construction_date
  @construction_date
end

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/building.rb', line 3

def height
  @height
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/building.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/building.rb', line 3

def name
  @name
end

Class Method Details

.allObject



19
20
21
22
# File 'lib/building.rb', line 19

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

.create(building_info) ⇒ Object



24
25
26
27
# File 'lib/building.rb', line 24

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

.find(input_id) ⇒ Object



14
15
16
17
# File 'lib/building.rb', line 14

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

Instance Method Details

#destroyObject



43
44
45
# File 'lib/building.rb', line 43

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

#update(input_options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/building.rb', line 29

def update(input_options)
  response = HTTP.patch(
                        "http://localhost:3000/api/buildings/#{@id}",
                        form: input_options
                        ).parse
  @id = response['id']
  @name = response['name']
  @address = response['address']
  @height = response['height']
  @construction_date = response['construction_date']
  @architect = response['architect']
  @image = response['image']
end