Module: HouseTest
- Defined in:
- lib/house_test.rb,
lib/house_test/version.rb,
lib/house_test/house_server.rb
Overview
Representing House objects in ‘backend’ (memory)
Constant Summary collapse
- PORT =
Port for server to run at
14_000
- VERSION =
'0.1.1'
Class Attribute Summary collapse
-
.houses ⇒ Object
Returns the value of attribute houses.
Class Method Summary collapse
-
.add(house_params = {}) ⇒ String
Add a new house according to parameters passed.
-
.delete(id) ⇒ Integer
Delete house at id.
-
.descriptions ⇒ String
Description of all houses.
-
.get(id) ⇒ House
Get an existing house.
-
.update(id, key, value) ⇒ Integer
Update house at id’s key to value.
Class Attribute Details
.houses ⇒ Object
Returns the value of attribute houses.
11 12 13 |
# File 'lib/house_test/house_server.rb', line 11 def houses @houses end |
Class Method Details
.add(house_params = {}) ⇒ String
Add a new house according to parameters passed
15 16 17 18 19 |
# File 'lib/house_test/house_server.rb', line 15 def add(house_params = {}) house = Backend::House.new(house_params) @houses << house house.id end |
.delete(id) ⇒ Integer
Delete house at id
42 43 44 45 46 47 48 |
# File 'lib/house_test/house_server.rb', line 42 def delete(id) found_house = get id return nil unless found_house houses.delete(found_house) id end |
.descriptions ⇒ String
Returns Description of all houses.
51 52 53 |
# File 'lib/house_test/house_server.rb', line 51 def descriptions houses.map(&:description) end |
.get(id) ⇒ House
Get an existing house
24 25 26 |
# File 'lib/house_test/house_server.rb', line 24 def get(id) houses.find { |house| house.id == id } end |
.update(id, key, value) ⇒ Integer
Update house at id’s key to value
31 32 33 34 35 36 37 |
# File 'lib/house_test/house_server.rb', line 31 def update(id, key, value) found_house = get id return nil unless found_house found_house.send("#{key}=", value) id end |