class DummyApartment
Constants
- ATTRIBUTES
- VERSION
- YML
Public Class Methods
gen_address()
click to toggle source
# File lib/dummy-apartment.rb, line 95 def self.gen_address prefs = @@dic['prefectures'] cities = @@dic['cities'] non_zero = (1..9).to_a.map(&:to_s) numbers = (0..9).to_a.map(&:to_s) street = non_zero.sample + numbers.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()
click to toggle source
# File lib/dummy-apartment.rb, line 109 def self.gen_building_name names = @@dic['building_name'] names['first_half'].sample + names['second_half'].sample end
gen_date_of_construction()
click to toggle source
# File lib/dummy-apartment.rb, line 162 def self.gen_date_of_construction rand(Date.new(1960, 1, 1) .. Date.today) end
gen_date_of_renovation(older_limit)
click to toggle source
# File lib/dummy-apartment.rb, line 166 def self.gen_date_of_renovation(older_limit) [true, false].sample ? rand(older_limit .. Date.today) : nil end
gen_deposit(monthly_rent)
click to toggle source
# File lib/dummy-apartment.rb, line 185 def self.gen_deposit(monthly_rent) [0, 1, 1, 1, 1, 2].sample * monthly_rent end
gen_finders_reward(monthly_rent)
click to toggle source
# File lib/dummy-apartment.rb, line 189 def self.gen_finders_reward(monthly_rent) [0, 1, 1, 1, 1, 2].sample * monthly_rent end
gen_lease_term(fixed)
click to toggle source
# File lib/dummy-apartment.rb, line 193 def self.gen_lease_term(fixed) return nil unless fixed rand(1 .. 3) end
gen_long_lat()
click to toggle source
# File lib/dummy-apartment.rb, line 114 def self.gen_long_lat # only around Kanto longitude = rand( 35.668559 .. 37.276341) latitude = rand(138.419373 .. 140.572693) [longitude, latitude] end
gen_management_fee()
click to toggle source
# File lib/dummy-apartment.rb, line 177 def self.gen_management_fee rand(0 .. 10) * 1000 end
gen_minutes_to_stations(num_of_stations)
click to toggle source
# File lib/dummy-apartment.rb, line 154 def self.gen_minutes_to_stations(num_of_stations) num_of_stations.times.with_object([]){ |i, array| on_foot = rand(1 .. 30) by_bus = rand(1 .. on_foot) array << {on_foot: on_foot, by_bus: by_bus} } end
gen_monthly_rent(occupied_area)
click to toggle source
# File lib/dummy-apartment.rb, line 170 def self.gen_monthly_rent(occupied_area) # base(15m^2) == 20000 # base(65^m2) == 340000 base = 80*occupied_area**2 + 2000 base.round(-3) + rand(-5 .. 5)*1000 end
gen_nearest_stations()
click to toggle source
# File lib/dummy-apartment.rb, line 149 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_occupied_area(type)
click to toggle source
# File lib/dummy-apartment.rb, line 139 def self.gen_occupied_area(type) chars = type.each_char.to_a num_rooms = chars.first.to_i + chars[1..-1].length num_rooms*10.0 + rand(-5.0 .. 5.0) end
gen_parking_price()
click to toggle source
# File lib/dummy-apartment.rb, line 181 def self.gen_parking_price rand(0 .. 10) * 1000 end
gen_renewal_fee(fixed, monthly_rent)
click to toggle source
# File lib/dummy-apartment.rb, line 198 def self.gen_renewal_fee(fixed, monthly_rent) return nil unless fixed rand(1 .. 3) * monthly_rent end
gen_room_floor(limit)
click to toggle source
# File lib/dummy-apartment.rb, line 126 def self.gen_room_floor(limit) rand(1 .. limit) end
gen_room_number(floor)
click to toggle source
# File lib/dummy-apartment.rb, line 130 def self.gen_room_number(floor) "#{floor}0#{rand(0..9)}" end
gen_room_type()
click to toggle source
# File lib/dummy-apartment.rb, line 134 def self.gen_room_type types = @@dic['room_type'] types.sample end
gen_top_floor()
click to toggle source
# File lib/dummy-apartment.rb, line 122 def self.gen_top_floor rand(2 .. 4) end
gen_true_or_false()
click to toggle source
# File lib/dummy-apartment.rb, line 145 def self.gen_true_or_false [true, false].sample end
generate()
click to toggle source
# 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 occupied_area = gen_occupied_area(room_type) keeping_pets = ['可', '不可', '要相談'].sample playing_the_instruments = ['可', '不可'].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 minutes_to_stations = gen_minutes_to_stations(nearest_stations.size) bath_toilet_separated = gen_true_or_false date_of_construction = gen_date_of_construction date_of_renovation = gen_date_of_renovation(date_of_construction) monthly_rent = gen_monthly_rent(occupied_area) management_fee = gen_management_fee parking_price = gen_parking_price deposit = gen_deposit(monthly_rent) finders_reward = gen_finders_reward(monthly_rent) fixed_term_lease = gen_true_or_false lease_term = gen_lease_term(fixed_term_lease) renewal_fee = gen_renewal_fee(fixed_term_lease, monthly_rent) values = ATTRIBUTES.map{ |attr| eval "#{attr}" } DummyApartment.new(Hash[ATTRIBUTES.zip values]) end
new(apartment_hash)
click to toggle source
# File lib/dummy-apartment.rb, line 55 def initialize(apartment_hash) assign_attributes(apartment_hash) end
Public Instance Methods
air_conditioner_equipped?()
click to toggle source
# File lib/dummy-apartment.rb, line 67 def air_conditioner_equipped? @air_conditioner_equipped end
bath_toilet_separated?()
click to toggle source
# File lib/dummy-apartment.rb, line 79 def bath_toilet_separated? @bath_toilet_separated end
fixed_term_lease?()
click to toggle source
# File lib/dummy-apartment.rb, line 87 def fixed_term_lease? @fixed_term_lease end
flooring?()
click to toggle source
# File lib/dummy-apartment.rb, line 59 def flooring? @floor_type == :flooring end
manager_patrol?()
click to toggle source
# File lib/dummy-apartment.rb, line 75 def manager_patrol? @manager_patrol end
renovated?()
click to toggle source
# File lib/dummy-apartment.rb, line 83 def renovated? !@date_of_renovation.nil? end
self_locking?()
click to toggle source
# File lib/dummy-apartment.rb, line 71 def self_locking? @self_locking end
tatami?()
click to toggle source
# File lib/dummy-apartment.rb, line 63 def tatami? @floor_type == :tatami end
to_hash()
click to toggle source
# File lib/dummy-apartment.rb, line 91 def to_hash Hash[ATTRIBUTES.map{|attr| [attr, instance_variable_get("@#{attr}")] }] end
Private Instance Methods
assign_attributes(hash)
click to toggle source
# File lib/dummy-apartment.rb, line 207 def assign_attributes(hash) ATTRIBUTES.each do |attr| self.instance_variable_set("@#{attr}".to_sym, hash[attr]) end end