Class: Building

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



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

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.



5
6
7
# File 'lib/poros_r_us.rb', line 5

def address
  @address
end

#architectObject

Returns the value of attribute architect.



5
6
7
# File 'lib/poros_r_us.rb', line 5

def architect
  @architect
end

#construction_dateObject

Returns the value of attribute construction_date.



5
6
7
# File 'lib/poros_r_us.rb', line 5

def construction_date
  @construction_date
end

#heightObject

Returns the value of attribute height.



5
6
7
# File 'lib/poros_r_us.rb', line 5

def height
  @height
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/poros_r_us.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/poros_r_us.rb', line 5

def name
  @name
end

Class Method Details

.allObject



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

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

.create(input_options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/poros_r_us.rb', line 25

def self.create(input_options)
  client_params = input_options
  response = HTTP.post(
                        "http://localhost:3000/api/buildings",
                        form: client_params
                        )

  created_building = response.parse

  Building.new(created_building)
end

.edit(input_id) ⇒ Object



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

def self.edit(input_id)
  response = HTTP.get("http://localhost:3000/api/buildings/#{input_id}")
  building_hash = response.parse
  render 'edit.html.erb'
end

.find(input_id) ⇒ Object



37
38
39
40
41
# File 'lib/poros_r_us.rb', line 37

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



62
63
64
# File 'lib/poros_r_us.rb', line 62

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

#update(input_options) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/poros_r_us.rb', line 50

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

  updated_building = response.parse

  Building.new(updated_building)
end