Class: Building

Inherits:
Object
  • Object
show all
Defined in:
lib/building_lookup.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
16
17
# File 'lib/building_lookup.rb', line 7

def initialize(input_options)
  # add attributes here as instance variables
 @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']
 @image = input_options['image']

end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



4
5
6
# File 'lib/building_lookup.rb', line 4

def address
  @address
end

#architectObject

Returns the value of attribute architect.



4
5
6
# File 'lib/building_lookup.rb', line 4

def architect
  @architect
end

#construction_dateObject

Returns the value of attribute construction_date.



4
5
6
# File 'lib/building_lookup.rb', line 4

def construction_date
  @construction_date
end

#heightObject

Returns the value of attribute height.



4
5
6
# File 'lib/building_lookup.rb', line 4

def height
  @height
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/building_lookup.rb', line 4

def id
  @id
end

#imageObject

Returns the value of attribute image.



4
5
6
# File 'lib/building_lookup.rb', line 4

def image
  @image
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/building_lookup.rb', line 4

def name
  @name
end

Class Method Details

.allObject



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

def self.all
  buildings = []
  response = HTTP.get("http://localhost:3000/api/buildings")
  response.parse.each do |building|
    buildings << Building.new(building)
  end 
  buildings
end

.create(building_params) ⇒ Object



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

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

.find(input_id) ⇒ Object



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

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

Instance Method Details

#destroyObject



56
57
58
59
# File 'lib/building_lookup.rb', line 56

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

end

#update(building_params) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/building_lookup.rb', line 42

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