Class: DummyApartment
- Inherits:
-
Object
- Object
- DummyApartment
- Defined in:
- lib/dummy-apartment.rb,
lib/dummy-apartment/version.rb
Constant Summary collapse
- YML =
File.('../data.yml', __FILE__)
- NON_ZERO =
(1..9).to_a.map(&:to_s)
- NUM =
NON_ZERO + ['0']
- NUM_DASH =
NUM + ['-']
- ATTRIBUTES =
%i(address building_name geo top_floor room_floor room_number room_type keeping_pets) + %i(playing_the_instruments place_for_washing_machine floor_type exposure) + %i(air_conditioner_equipped self_locking manager_patrol nearest_stations)
- VERSION =
"0.1.0"
Class Method Summary collapse
- .gen_address ⇒ Object
- .gen_building_name ⇒ Object
- .gen_long_lat ⇒ Object
- .gen_nearest_stations ⇒ Object
- .gen_room_floor(limit) ⇒ Object
- .gen_room_number(floor) ⇒ Object
- .gen_room_type ⇒ Object
- .gen_top_floor ⇒ Object
- .gen_true_or_false ⇒ Object
- .generate ⇒ Object
Instance Method Summary collapse
- #air_conditioner_equipped? ⇒ Boolean
- #flooring? ⇒ Boolean
-
#initialize(apartment_hash) ⇒ DummyApartment
constructor
A new instance of DummyApartment.
- #manager_patrol? ⇒ Boolean
- #self_locking? ⇒ Boolean
- #tatami? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(apartment_hash) ⇒ DummyApartment
Returns a new instance of DummyApartment.
42 43 44 |
# File 'lib/dummy-apartment.rb', line 42 def initialize(apartment_hash) assign_attributes(apartment_hash) end |
Class Method Details
.gen_address ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dummy-apartment.rb', line 70 def self.gen_address prefs = @@dic['prefectures'] cities = @@dic['cities'] street = NON_ZERO.sample + NUM.sample(rand 1..3).join dash_index = rand(street.length-1) street.insert(dash_index, '-') if dash_index != 0 and dash_index != street.length [prefs.sample, cities.sample, street].join end |
.gen_building_name ⇒ Object
81 82 83 84 |
# File 'lib/dummy-apartment.rb', line 81 def self.gen_building_name names = @@dic['building_name'] names['first_half'].sample + names['second_half'].sample end |
.gen_long_lat ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/dummy-apartment.rb', line 86 def self.gen_long_lat # only around Kanto longitude = rand( 35.668559 .. 37.276341) latitude = rand(138.419373 .. 140.572693) [longitude, latitude] end |
.gen_nearest_stations ⇒ Object
115 116 117 118 |
# File 'lib/dummy-apartment.rb', line 115 def self.gen_nearest_stations number = Math.sqrt(rand 1..4).floor # 1 with 3/4, 2 with 1/4 @@dic['station'].sample number end |
.gen_room_floor(limit) ⇒ Object
98 99 100 |
# File 'lib/dummy-apartment.rb', line 98 def self.gen_room_floor(limit) rand(1 .. limit) end |
.gen_room_number(floor) ⇒ Object
102 103 104 |
# File 'lib/dummy-apartment.rb', line 102 def self.gen_room_number(floor) "#{floor}0#{rand(0..9)}" end |
.gen_room_type ⇒ Object
106 107 108 109 |
# File 'lib/dummy-apartment.rb', line 106 def self.gen_room_type types = @@dic['room_type'] types.sample end |
.gen_top_floor ⇒ Object
94 95 96 |
# File 'lib/dummy-apartment.rb', line 94 def self.gen_top_floor rand(2 .. 4) end |
.gen_true_or_false ⇒ Object
111 112 113 |
# File 'lib/dummy-apartment.rb', line 111 def self.gen_true_or_false [true, false].sample end |
.generate ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dummy-apartment.rb', line 20 def self.generate address = gen_address building_name = gen_building_name geo = gen_long_lat top_floor = gen_top_floor room_floor = gen_room_floor(top_floor) room_number = gen_room_number(room_floor) room_type = gen_room_type keeping_pets = ['可', '不可', '要相談'].sample = ['可', '不可'].sample place_for_washing_machine = ['室内', '室外', '無し'].sample floor_type = [:flooring, :tatami].sample exposure = [:north, :south, :east, :west].sample air_conditioner_equipped = gen_true_or_false self_locking = gen_true_or_false manager_patrol = gen_true_or_false nearest_stations = gen_nearest_stations values = ATTRIBUTES.map{ |attr| eval "#{attr}" } DummyApartment.new(Hash[ATTRIBUTES.zip values]) end |
Instance Method Details
#air_conditioner_equipped? ⇒ Boolean
54 55 56 |
# File 'lib/dummy-apartment.rb', line 54 def air_conditioner_equipped? @air_conditioner_equipped end |
#flooring? ⇒ Boolean
46 47 48 |
# File 'lib/dummy-apartment.rb', line 46 def flooring? @floor_type == :flooring end |
#manager_patrol? ⇒ Boolean
62 63 64 |
# File 'lib/dummy-apartment.rb', line 62 def manager_patrol? @manager_patrol end |
#self_locking? ⇒ Boolean
58 59 60 |
# File 'lib/dummy-apartment.rb', line 58 def self_locking? @self_locking end |
#tatami? ⇒ Boolean
50 51 52 |
# File 'lib/dummy-apartment.rb', line 50 def tatami? @floor_type == :tatami end |
#to_hash ⇒ Object
66 67 68 |
# File 'lib/dummy-apartment.rb', line 66 def to_hash Hash[ATTRIBUTES.map{|attr| [attr, instance_variable_get("@#{attr}")] }] end |