Class: Building

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

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 (readonly)

Returns the value of attribute address.



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

def address
  @address
end

#architectObject (readonly)

Returns the value of attribute architect.



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

def architect
  @architect
end

#construction_dateObject (readonly)

Returns the value of attribute construction_date.



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

def construction_date
  @construction_date
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allObject



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

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

.create(input_options) ⇒ Object



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

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

.find(input_id) ⇒ Object



15
16
17
18
# File 'lib/b_rabbit.rb', line 15

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

Instance Method Details

#destroyObject



39
40
41
# File 'lib/b_rabbit.rb', line 39

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

#update(input_options) ⇒ Object



32
33
34
35
36
37
# File 'lib/b_rabbit.rb', line 32

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