dummy-apartment 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49c7b373277d13ea9e273cc82d0964bce85de2be
4
- data.tar.gz: 188d14ebc395f91283b779dd1a5b7b680405b2fa
3
+ metadata.gz: 9563bee67f5469fc997907410ac6db6af98f362e
4
+ data.tar.gz: 63f10965fb3110d8d45a2434aeab6f712392870d
5
5
  SHA512:
6
- metadata.gz: f62ce22f2174f9ceec7eaae9a1bbc74602d9299e347325e13400a5edc2605444fbf3a4a6fcc9048f3c69cae0b5c7d5de803907dfe5699030f5df23fa71dda294
7
- data.tar.gz: b0e42004449f0ef8bce267dcad776d866b401eddea81aad9de0d90eed158216ffe82fd5e5cb22fcae761ce78c87b2349a228ca50be82dd0fbab49dfd25083273
6
+ metadata.gz: afa71aa5c7a367a4fb16a07337e9072de2e8f20c8ba0c17d2a4490c6f7a94884a3f020e8dc9e732510346b8ad19277d379c548adb8c2319f19e199196e03452f
7
+ data.tar.gz: d74290cd5b5e7c118f55eb9559d9738c1891225c2a2ac9b63f0b0524c12ab902445d135134c224c3d621a315bcb84f2c42e3ad7ca19dc04ddf7be57c92f67d4f
data/README.md CHANGED
@@ -11,6 +11,11 @@ This gem generates dummy information of apartment including
11
11
  * keeping pets
12
12
  * playable the musical instruments or not
13
13
  * floor type
14
+ * direction the window facing
15
+ * air conditioner is equipped or not
16
+ * is self-locking door?
17
+ * whether the manager patrols
18
+ * names of closest stations
14
19
 
15
20
  ### Installation
16
21
 
@@ -32,12 +37,17 @@ Or just:
32
37
 
33
38
  apartment = DummyApartment.generate
34
39
 
40
+ # Get attributes
35
41
  apartment.address #=> "群馬県長谷市60"
36
42
  apartment.building_name #=> "石井コーポ"
37
- apartment_room_floor #=> 2
43
+ apartment.room_floor #=> 2
38
44
 
39
- apartment[:room_floor] #=> 2
40
- apartment['room_floor'] #=> 2
45
+ # Overwrite
46
+ apartment.building_name = "ハイツ谷川"
47
+
48
+ # Convert to Hash
49
+ apartment.to_hash
50
+ #=> {address: "群馬県長谷市60", building_name: "ハイツ谷川", ... }
41
51
 
42
52
  ### Contributing
43
53
 
data/lib/data.yml CHANGED
@@ -4,3 +4,4 @@ building_name:
4
4
  first_half: ["石井", "山城", "大井台", "片山", "大山", "植木", "長嶺", "東", "南", "西", "北", "市橋", "富岡", "田町", "江頭", "ポール", "牧", "片岡", "鶴", "太郎", "メゾン・ド", "SAKURA", "紫", "碧"]
5
5
  second_half: ["コーポ", "ハイツ", "サンハイツ", "メゾン", "パレス", "ネオパレス", "プロミネンス", "カーサ", "Petit", "プチトマト", "パーク", "ネックス", "エスポワール", "エクセル", "グラン", "コンフォート", "エトワール", "フローラ", "リバティ", "荘"]
6
6
  room_type: ["1R", "1K", "1DK", "1LDK", "2K", "2DK", "2LDK", "3K", "3DK", "3LDK"]
7
+ station: ["城東駅", "庄内駅", "白浜駅", "白石駅", "武田駅", "望月駅", "和田駅", "久保駅", "心斎橋駅", "仁木駅", "西ヶ原駅", "東駅", "西駅", "南駅", "北駅", "酒田駅", "桜木駅", "鯖江駅", "藤江駅", "富士見駅", "古川駅", "保見駅", "元町駅", "三雲駅", "水沢駅", "緑駅", "峰山駅", "宮下駅", "武蔵駅", "村山駅", "芝田駅", "中島駅", "鳴門駅", "小岩井駅", "郷間駅", "櫛田駅", "広井公園駅", "ヨウ素駅"]
@@ -12,74 +12,59 @@ class DummyApartment
12
12
  @@dic ||= Psych.load(File.open(YML).read)
13
13
 
14
14
  ATTRIBUTES = %i(address building_name geo top_floor room_floor room_number room_type keeping_pets) +
15
- %i(playing_the_instruments place_for_washing_machine floor_type)
15
+ %i(playing_the_instruments place_for_washing_machine floor_type exposure) +
16
+ %i(air_conditioner_equipped self_locking manager_patrol nearest_stations)
16
17
 
17
- attr_reader *ATTRIBUTES
18
+ attr_accessor *ATTRIBUTES
18
19
 
19
20
  def self.generate
20
- address = gen_address
21
- building_name = gen_building_name
22
- geo = gen_long_lat
23
- top_floor = gen_top_floor
24
- room_floor = gen_room_floor(top_floor)
25
- room_number = gen_room_number(room_floor)
26
- room_type = gen_room_type
27
- keeping_pets = gen_keeping_pets
28
- playing_the_instruments = gen_playing_the_instruments
29
- place_for_washing_machine = gen_place_for_washing_machine
30
- floor_type = gen_floor_type
21
+ address = gen_address
22
+ building_name = gen_building_name
23
+ geo = gen_long_lat
24
+ top_floor = gen_top_floor
25
+ room_floor = gen_room_floor(top_floor)
26
+ room_number = gen_room_number(room_floor)
27
+ room_type = gen_room_type
28
+ keeping_pets = ['可', '不可', '要相談'].sample
29
+ playing_the_instruments = ['可', '不可'].sample
30
+ place_for_washing_machine = ['室内', '室外', '無し'].sample
31
+ floor_type = [:flooring, :tatami].sample
32
+ exposure = [:north, :south, :east, :west].sample
33
+ air_conditioner_equipped = gen_true_or_false
34
+ self_locking = gen_true_or_false
35
+ manager_patrol = gen_true_or_false
36
+ nearest_stations = gen_nearest_stations
31
37
 
32
38
  values = ATTRIBUTES.map{ |attr| eval "#{attr}" }
33
39
  DummyApartment.new(Hash[ATTRIBUTES.zip values])
34
40
  end
35
41
 
36
42
  def initialize(apartment_hash)
37
- @hash = apartment_hash
38
- assign_attributes
43
+ assign_attributes(apartment_hash)
39
44
  end
40
45
 
41
- def [](key)
42
- case key
43
- when String; @hash[key.to_sym]
44
- when Symbol; @hash[key]
45
- else; raise
46
- end
46
+ def flooring?
47
+ @floor_type == :flooring
47
48
  end
48
49
 
49
- def []=(key, value)
50
- case key
51
- when String; assign(key.to_sym, value)
52
- when Symbol; assign(key, value)
53
- else; raise
54
- end
50
+ def tatami?
51
+ @floor_type == :tatami
55
52
  end
56
53
 
57
- def assign(key, value)
58
- if ATTRIBUTES.member? key
59
- @hash[key] = value
60
- instance_variable_set("@#{key}".to_sym, value)
61
- end
54
+ def air_conditioner_equipped?
55
+ @air_conditioner_equipped
62
56
  end
63
57
 
64
- ATTRIBUTES.each do |attr|
65
- eval <<-RUBY
66
- def #{attr}=(value)
67
- @hash[:#{attr}] = value
68
- @#{attr} = value
69
- end
70
- RUBY
58
+ def self_locking?
59
+ @self_locking
71
60
  end
72
61
 
73
- def flooring?
74
- @floor_type == :flooring
62
+ def manager_patrol?
63
+ @manager_patrol
75
64
  end
76
65
 
77
- def tatami?
78
- @floor_type == :tatami
79
- end
80
-
81
- def method_missing(method_name, *args)
82
- @hash.send(method_name, *args) if @hash.respond_to? method_name
66
+ def to_hash
67
+ Hash[ATTRIBUTES.map{|attr| [attr, instance_variable_get("@#{attr}")] }]
83
68
  end
84
69
 
85
70
  def self.gen_address
@@ -123,29 +108,22 @@ class DummyApartment
123
108
  types.sample
124
109
  end
125
110
 
126
- def self.gen_keeping_pets
127
- ['可', '不可', '要相談'].sample
128
- end
129
-
130
- def self.gen_playing_the_instruments
131
- ['可', '不可'].sample
132
- end
133
-
134
- def self.gen_place_for_washing_machine
135
- ['室内', '室外', '無し'].sample
111
+ def self.gen_true_or_false
112
+ [true, false].sample
136
113
  end
137
114
 
138
- def self.gen_floor_type
139
- [:flooring, :tatami].sample
115
+ def self.gen_nearest_stations
116
+ number = Math.sqrt(rand 1..4).floor # 1 with 3/4, 2 with 1/4
117
+ @@dic['station'].sample number
140
118
  end
141
119
 
142
120
  private_class_method *self.public_methods.grep(/\Agen_/)
143
121
 
144
122
  private
145
123
 
146
- def assign_attributes
124
+ def assign_attributes(hash)
147
125
  ATTRIBUTES.each do |attr|
148
- self.instance_variable_set("@#{attr}".to_sym, @hash[attr])
126
+ self.instance_variable_set("@#{attr}".to_sym, hash[attr])
149
127
  end
150
128
  end
151
129
  end
@@ -1,4 +1,4 @@
1
1
  class DummyApartment
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
4
4
 
@@ -9,32 +9,29 @@ describe DummyApartment do
9
9
  expect(@apartment).to be_a DummyApartment
10
10
  end
11
11
 
12
- it 'should delegate to Hash' do
13
- expect(@apartment.respond_to? :keys).to be_false
14
- expect(@apartment.keys).to be_an Array
15
- end
16
-
17
- it 'should access the attribute via the method which has same name as the attribute' do
18
- expect(@apartment.room_number).to eql @apartment[:room_number]
19
- expect(@apartment.address).to eql @apartment[:address]
20
- end
12
+ describe 'to_hash Method' do
13
+ it 'should return a Hash object' do
14
+ expect(@apartment.to_hash).to be_a Hash
15
+ end
21
16
 
22
- it 'should access the attribute using both String and Symbol' do
23
- expect(@apartment['address']).to eql @apartment.address
24
- expect(@apartment[:address]).to eql @apartment.address
25
- end
17
+ describe 'The Hash' do
18
+ it 'should consist with the DummyApartment object' do
19
+ hash = @apartment.to_hash
20
+ DummyApartment::ATTRIBUTES.each do |attr|
21
+ expect(hash[attr]).to eql @apartment.send(attr)
22
+ end
26
23
 
27
- it 'should be overwritten its attributes' do
28
- @apartment.address = ''
29
- expect(@apartment.address).to be_empty
30
- @apartment[:address] = 'somewhere'
31
- expect(@apartment.address).to eql 'somewhere'
24
+ @apartment.address = 'somewhere'
25
+ expect(@apartment.to_hash[:address]).to eql 'somewhere'
26
+ end
27
+ end
32
28
  end
33
29
 
34
- it 'should have consistency' do
35
- @apartment.address = 'somewhere'
36
- expect(@apartment.address).to eql @apartment[:address]
37
- expect(@apartment.address).to eql @apartment['address']
30
+ it 'should have the accessor methods' do
31
+ DummyApartment::ATTRIBUTES.each do |attr|
32
+ expect(@apartment.respond_to? attr).to be_true
33
+ expect(@apartment.respond_to? "#{attr}=").to be_true
34
+ end
38
35
  end
39
36
 
40
37
  it 'should raise when pass an argument which is not String or Symbol' do
@@ -47,121 +44,190 @@ describe DummyApartment do
47
44
  end
48
45
 
49
46
  describe 'Building Name' do
50
- let(:name){ @apartment[:building_name] }
51
-
52
47
  it 'should not be empty' do
53
- expect(name).not_to be_empty
48
+ 100.times do
49
+ expect(Build.building_name).not_to be_empty
50
+ end
54
51
  end
55
52
  end
56
53
 
57
54
  describe 'Address' do
58
- let(:address){ @apartment[:address] }
59
-
60
55
  it 'should match address format' do
61
- expect(address).to match /[都道府県].+[市町村].*[0-9]/
56
+ 100.times do
57
+ expect(Build.address).to match /[都道府県].+[市町村].*[0-9]/
58
+ end
62
59
  end
63
60
  end
64
61
 
65
62
  describe 'Geo' do
66
- let(:geo){ @apartment[:geo] }
67
-
68
63
  it 'should be a couple of Float' do
69
- expect(geo.map(&:class)).to eql [Float, Float]
64
+ expect(Build.geo.map(&:class)).to eql [Float, Float]
70
65
  end
71
66
  end
72
67
 
73
68
  describe 'Room Floor and Top Floor' do
74
- let(:top_floor) { @apartment[:top_floor] }
75
- let(:room_floor){ @apartment[:room_floor] }
76
-
77
69
  it 'should have valid floor information' do
78
- expect( top_floor).to be >= room_floor
79
- expect( top_floor).to be >= 1
80
- expect(room_floor).to be >= 1
70
+ 100.times do
71
+ top_floor, room_floor = Build[:top_floor, :room_floor]
72
+
73
+ expect( top_floor).to be >= room_floor
74
+ expect( top_floor).to be >= 1
75
+ expect(room_floor).to be >= 1
76
+ end
81
77
  end
82
78
  end
83
79
 
84
80
  describe 'Room Number' do
85
- let(:room_floor) { @apartment[:room_floor] }
86
- let(:room_number){ @apartment[:room_number] }
87
-
88
81
  it 'should be a three-character string' do
82
+ room_number = Build.room_number
83
+
89
84
  expect(room_number).to be_a String
90
85
  expect(room_number.length).to eql 3
91
86
  end
92
87
 
93
88
  it 'should be consistent with room floor' do
94
- expect(room_number).to start_with room_floor.to_s
89
+ 100.times do
90
+ room_number, room_floor = Build[:room_number, :room_floor]
91
+ expect(room_number).to start_with room_floor.to_s
92
+ end
95
93
  end
96
94
  end
97
95
 
98
96
  describe 'Room Type' do
99
- let(:room_type){ @apartment[:room_type] }
97
+ let(:room_type){ @apartment.room_type }
100
98
 
101
99
  it 'should be a String object' do
102
- expect(room_type).to be_a String
100
+ expect(Build.room_type).to be_a String
103
101
  end
104
102
 
105
103
  it 'should be match the format' do
106
- expect(room_type).to match /\A\d(R|[LDK]{1,3})\z/
104
+ 100.times do
105
+ expect(Build.room_type).to match /\A\d(R|[LDK]{1,3})\z/
106
+ end
107
107
  end
108
108
  end
109
109
 
110
110
  describe 'Keeping Pets' do
111
- let(:keeping_pets){ @apartment[:keeping_pets] }
112
-
113
111
  it 'should be a String object' do
114
- expect(keeping_pets).to be_a String
112
+ expect(Build.keeping_pets).to be_a String
115
113
  end
116
114
 
117
115
  it 'should equal "可", "不可" or "要相談"' do
118
- expect(keeping_pets).to match /\A(可|不可|要相談)\z/
116
+ 100.times do
117
+ expect(Build.keeping_pets).to match /\A(可|不可|要相談)\z/
118
+ end
119
119
  end
120
120
  end
121
121
 
122
122
  describe 'Playing the Instruments' do
123
- let(:playing_the_instruments){ @apartment[:playing_the_instruments] }
124
-
125
123
  it 'should be a String object' do
126
- expect(playing_the_instruments).to be_a String
124
+ expect(Build.playing_the_instruments).to be_a String
127
125
  end
128
126
 
129
127
  it 'should equal "可" or "不可"' do
130
- expect(playing_the_instruments).to match /\A不?可\z/
128
+ 100.times do
129
+ expect(Build.playing_the_instruments).to match /\A不?可\z/
130
+ end
131
131
  end
132
132
  end
133
133
 
134
134
  describe 'Place for Washing Machine' do
135
- let(:place_for_washing_machine){ @apartment[:place_for_washing_machine] }
136
-
137
135
  it 'should be a String object' do
138
- expect(place_for_washing_machine).to be_a String
136
+ expect(Build.place_for_washing_machine).to be_a String
139
137
  end
140
138
 
141
139
  it 'should equal "室内", "室外" or "無し"' do
142
- expect(place_for_washing_machine).to match /\A(室内|室外|無し)\z/
140
+ 100.times do
141
+ expect(Build.place_for_washing_machine).to match /\A(室内|室外|無し)\z/
142
+ end
143
143
  end
144
144
  end
145
145
 
146
146
  describe 'Floor Type' do
147
- let(:floor_type){ @apartment[:floor_type] }
148
-
149
147
  it 'should be a Symbol' do
150
- expect(floor_type).to be_a Symbol
148
+ expect(Build.floor_type).to be_a Symbol
151
149
  end
152
150
 
153
151
  it 'should equal :flooring or :tatami' do
154
- expect([:flooring, :tatami]).to include floor_type
152
+ 100.times do
153
+ expect([:flooring, :tatami]).to include Build.floor_type
154
+ end
155
155
  end
156
156
 
157
157
  it 'should consistent between #floor_type, #tatami? and #flooring?' do
158
- case floor_type
159
- when :flooring
160
- expect(@apartment.flooring?).to be_true
161
- expect(@apartment.tatami?).to be_false
162
- when :tatami
163
- expect(@apartment.flooring?).to be_false
164
- expect(@apartment.tatami?).to be_true
158
+ 100.times do
159
+ apartment = DummyApartment.generate
160
+
161
+ case apartment.floor_type
162
+ when :flooring
163
+ expect(apartment.flooring?).to be_true
164
+ expect(apartment.tatami?).to be_false
165
+ when :tatami
166
+ expect(apartment.flooring?).to be_false
167
+ expect(apartment.tatami?).to be_true
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ describe 'Exposure' do
174
+ it 'should be a Symbol' do
175
+ expect(Build.exposure).to be_a Symbol
176
+ end
177
+
178
+ it 'should be equal :north, :south, :east or :west' do
179
+ 100.times do
180
+ expect([:north, :south, :east, :west]).to include Build.exposure
181
+ end
182
+ end
183
+ end
184
+
185
+ describe 'Air Conditioner' do
186
+ it 'should be consist between #air_conditioner_equipped and #air_conditioner_equipped?' do
187
+ 100.times do
188
+ apartment = DummyApartment.generate
189
+ expect(apartment.air_conditioner_equipped).to eql apartment.air_conditioner_equipped?
190
+ end
191
+ end
192
+ end
193
+
194
+ describe 'Self Locking' do
195
+ it 'should be consist between #self_locking and #self_locking?' do
196
+ 100.times do
197
+ apartment = DummyApartment.generate
198
+ expect(apartment.self_locking).to eql apartment.self_locking?
199
+ end
200
+ end
201
+ end
202
+
203
+ describe "Manager's Patrol" do
204
+ it 'should be consist between #manager_patrol and #manager_patrol?' do
205
+ 100.times do
206
+ apartment = DummyApartment.generate
207
+ expect(apartment.manager_patrol).to eql apartment.manager_patrol?
208
+ end
209
+ end
210
+ end
211
+
212
+ describe 'Nearest Stations' do
213
+ let(:nearest_stations){ @apartment.nearest_stations }
214
+
215
+ it 'should be an Array of Strings' do
216
+ expect(nearest_stations).to be_an Array
217
+ expect(nearest_stations.all?{|s| String === s}).to be_true
218
+ end
219
+
220
+ it 'should be an Array whose size is one or two' do
221
+ 100.times do
222
+ expect(Build.nearest_stations.size).to be_between(1, 2)
223
+ end
224
+ end
225
+
226
+ describe "Stations' Name" do
227
+ it "should end with '駅'" do
228
+ 100.times do
229
+ expect(Build.nearest_stations.all?{|name| name.end_with? '駅'}).to be_true
230
+ end
165
231
  end
166
232
  end
167
233
  end
data/spec/spec_helper.rb CHANGED
@@ -2,3 +2,18 @@ lib = File.expand_path('../../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  require 'dummy-apartment'
5
+
6
+ module Build
7
+ def [](*args)
8
+ apartment = DummyApartment.generate
9
+ args.each_with_object([]) { |arg, array|
10
+ array << apartment.send(arg)
11
+ }
12
+ end
13
+
14
+ def method_missing(name, *args)
15
+ DummyApartment.generate.send(name, *args)
16
+ end
17
+
18
+ module_function :[], :method_missing
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dummy-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe-noh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-17 00:00:00.000000000 Z
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler