dummy-apartment 0.1.0 → 0.1.1

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: 9563bee67f5469fc997907410ac6db6af98f362e
4
- data.tar.gz: 63f10965fb3110d8d45a2434aeab6f712392870d
3
+ metadata.gz: 724ea1784d40a1e3cfc7d729b2679d51639efa21
4
+ data.tar.gz: e8a1bd601a0e6f06f8131b4e7f282b411234d457
5
5
  SHA512:
6
- metadata.gz: afa71aa5c7a367a4fb16a07337e9072de2e8f20c8ba0c17d2a4490c6f7a94884a3f020e8dc9e732510346b8ad19277d379c548adb8c2319f19e199196e03452f
7
- data.tar.gz: d74290cd5b5e7c118f55eb9559d9738c1891225c2a2ac9b63f0b0524c12ab902445d135134c224c3d621a315bcb84f2c42e3ad7ca19dc04ddf7be57c92f67d4f
6
+ metadata.gz: e704dc4e4815adf7280e835ac1d39eafb41802c42f95ba93a8375f13261175caf7aaa14298a2224fc5f7aa2eff4bcf066b3f6a9a9a122ae4a76d013563bacb97
7
+ data.tar.gz: af07e4bbf5b0071f1698bdbaf18e81e9c17e5183454811cad22de83a874673794830849957912564ad90c9aa280eb558e2c56d33ed8008ea4d10addc34518af7
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ script: "bundle exec rspec"
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ notifications:
7
+ email:
8
+ on_success: never
9
+ on_failure: never
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## DummyApartment
2
+ [![Build Status](https://travis-ci.org/Joe-noh/dummy-apartment.png)](https://travis-ci.org/Joe-noh/dummy-apartment)
3
+ [![Gem Version](https://badge.fury.io/rb/dummy-apartment.png)](http://badge.fury.io/rb/dummy-apartment)
2
4
 
3
5
  This gem generates dummy information of apartment including
4
6
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'dummy-apartment/version'
4
+ require 'dummy-apartment'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "dummy-apartment"
@@ -1,19 +1,19 @@
1
- require "dummy-apartment/version"
1
+ #-*- coding: utf-8 -*-
2
2
 
3
3
  require 'psych'
4
+ require 'date'
4
5
 
5
6
  class DummyApartment
7
+ VERSION = "0.1.1"
6
8
  YML = File.expand_path('../data.yml', __FILE__)
7
9
 
8
- NON_ZERO = (1..9).to_a.map(&:to_s)
9
- NUM = NON_ZERO + ['0']
10
- NUM_DASH = NUM + ['-']
11
-
12
10
  @@dic ||= Psych.load(File.open(YML).read)
13
11
 
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 exposure) +
16
- %i(air_conditioner_equipped self_locking manager_patrol nearest_stations)
12
+ ATTRIBUTES = [:address, :building_name, :geo, :top_floor, :room_floor, :room_number, :room_type,
13
+ :keeping_pets, :playing_the_instruments, :place_for_washing_machine, :floor_type,
14
+ :exposure, :air_conditioner_equipped, :self_locking, :manager_patrol, :nearest_stations,
15
+ :minutes_to_stations, :occupied_area, :bath_toilet_separated, :date_of_construction,
16
+ :date_of_renovation]
17
17
 
18
18
  attr_accessor *ATTRIBUTES
19
19
 
@@ -25,6 +25,7 @@ class DummyApartment
25
25
  room_floor = gen_room_floor(top_floor)
26
26
  room_number = gen_room_number(room_floor)
27
27
  room_type = gen_room_type
28
+ occupied_area = gen_occupied_area(room_type)
28
29
  keeping_pets = ['可', '不可', '要相談'].sample
29
30
  playing_the_instruments = ['可', '不可'].sample
30
31
  place_for_washing_machine = ['室内', '室外', '無し'].sample
@@ -34,6 +35,10 @@ class DummyApartment
34
35
  self_locking = gen_true_or_false
35
36
  manager_patrol = gen_true_or_false
36
37
  nearest_stations = gen_nearest_stations
38
+ minutes_to_stations = gen_minutes_to_stations(nearest_stations.size)
39
+ bath_toilet_separated = gen_true_or_false
40
+ date_of_construction = gen_date_of_construction
41
+ date_of_renovation = gen_date_of_renovation(date_of_construction)
37
42
 
38
43
  values = ATTRIBUTES.map{ |attr| eval "#{attr}" }
39
44
  DummyApartment.new(Hash[ATTRIBUTES.zip values])
@@ -63,6 +68,14 @@ class DummyApartment
63
68
  @manager_patrol
64
69
  end
65
70
 
71
+ def bath_toilet_separated?
72
+ @bath_toilet_separated
73
+ end
74
+
75
+ def renovated?
76
+ !@date_of_renovation.nil?
77
+ end
78
+
66
79
  def to_hash
67
80
  Hash[ATTRIBUTES.map{|attr| [attr, instance_variable_get("@#{attr}")] }]
68
81
  end
@@ -71,7 +84,10 @@ class DummyApartment
71
84
  prefs = @@dic['prefectures']
72
85
  cities = @@dic['cities']
73
86
 
74
- street = NON_ZERO.sample + NUM.sample(rand 1..3).join
87
+ non_zero = (1..9).to_a.map(&:to_s)
88
+ numbers = (0..9).to_a.map(&:to_s)
89
+
90
+ street = non_zero.sample + numbers.sample(rand 1..3).join
75
91
  dash_index = rand(street.length-1)
76
92
  street.insert(dash_index, '-') if dash_index != 0 and dash_index != street.length
77
93
 
@@ -108,6 +124,12 @@ class DummyApartment
108
124
  types.sample
109
125
  end
110
126
 
127
+ def self.gen_occupied_area(type)
128
+ chars = type.each_char.to_a
129
+ num_rooms = chars.first.to_i + chars[1..-1].length
130
+ num_rooms*10.0 + rand(-5.0 .. 5.0)
131
+ end
132
+
111
133
  def self.gen_true_or_false
112
134
  [true, false].sample
113
135
  end
@@ -117,6 +139,22 @@ class DummyApartment
117
139
  @@dic['station'].sample number
118
140
  end
119
141
 
142
+ def self.gen_minutes_to_stations(num_of_stations)
143
+ num_of_stations.times.with_object([]){ |i, array|
144
+ on_foot = rand(1 .. 30)
145
+ by_bus = rand(1 .. on_foot)
146
+ array << {on_foot: on_foot, by_bus: by_bus}
147
+ }
148
+ end
149
+
150
+ def self.gen_date_of_construction
151
+ rand(Date.new(1960, 1, 1) .. Date.today)
152
+ end
153
+
154
+ def self.gen_date_of_renovation(older_limit)
155
+ [true, false].sample ? rand(older_limit .. Date.today) : nil
156
+ end
157
+
120
158
  private_class_method *self.public_methods.grep(/\Agen_/)
121
159
 
122
160
  private
@@ -1,3 +1,5 @@
1
+ #-*- coding: utf-8 -*-
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'data.yml' do
@@ -9,4 +11,4 @@ describe 'data.yml' do
9
11
  expect(dic['building_name'][ 'first_half'] - dic['building_name'][ 'first_half'].uniq).to be_empty
10
12
  expect(dic['building_name']['second_half'] - dic['building_name']['second_half'].uniq).to be_empty
11
13
  end
12
- end
14
+ end
@@ -1,3 +1,5 @@
1
+ #-*- coding: utf-8 -*-
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DummyApartment do
@@ -107,6 +109,27 @@ describe DummyApartment do
107
109
  end
108
110
  end
109
111
 
112
+ describe 'Occupied Area' do
113
+ it 'should be correspond to room_type' do
114
+ 100.times do
115
+ type, area = Build[:room_type, :occupied_area]
116
+ range = case type
117
+ when '1R'; (15.0 .. 25.0)
118
+ when '1K'; (15.0 .. 25.0)
119
+ when '1DK'; (25.0 .. 35.0)
120
+ when '1LDK'; (35.0 .. 45.0)
121
+ when '2K'; (25.0 .. 35.0)
122
+ when '2DK'; (35.0 .. 45.0)
123
+ when '2LDK'; (45.0 .. 55.0)
124
+ when '3K'; (35.0 .. 45.0)
125
+ when '3DK'; (45.0 .. 55.0)
126
+ when '3LDK'; (55.0 .. 65.0)
127
+ end
128
+ expect(range).to include area
129
+ end
130
+ end
131
+ end
132
+
110
133
  describe 'Keeping Pets' do
111
134
  it 'should be a String object' do
112
135
  expect(Build.keeping_pets).to be_a String
@@ -231,4 +254,75 @@ describe DummyApartment do
231
254
  end
232
255
  end
233
256
  end
257
+
258
+ describe 'Minutes to Stations' do
259
+ let(:minutes_to_stations){ @apartment.minutes_to_stations }
260
+
261
+ it 'should be an Array of Hashes' do
262
+ expect(minutes_to_stations).to be_an Array
263
+ expect(minutes_to_stations.all?{|h| Hash === h}).to be_true
264
+ end
265
+
266
+ it 'should be an Array the size of which is equal to of nearest_stations' do
267
+ 100.times do
268
+ nearests, minutes = Build[:nearest_stations, :minutes_to_stations]
269
+ expect(nearests.size).to eql minutes.size
270
+ end
271
+ end
272
+
273
+ it 'should have relation on_foot >= by_bus' do
274
+ 100.times do
275
+ minutes = Build.minutes_to_stations.first
276
+ on_foot = minutes[:on_foot]
277
+ by_bus = minutes[:by_bus]
278
+
279
+ expect(on_foot).to be >= by_bus
280
+ end
281
+ end
282
+ end
283
+
284
+ describe 'Bath and Toilet' do
285
+ it 'should be consist between #bath_toilet_separated and #bath_toilet_separated?' do
286
+ 100.times do
287
+ apartment = DummyApartment.generate
288
+ expect(apartment.bath_toilet_separated).to eql apartment.bath_toilet_separated?
289
+ end
290
+ end
291
+ end
292
+
293
+ describe 'Date the Building was Built' do
294
+ it 'should be a Date object' do
295
+ expect(@apartment.date_of_construction).to be_a Date
296
+ end
297
+
298
+ it 'should be newer than Jan 1 1960' do
299
+ 100.times do
300
+ diff = Build.date_of_construction - Date.new(1960, 1, 1)
301
+ expect(diff).to be >= 0
302
+ end
303
+ end
304
+ end
305
+
306
+ describe 'Date of Renovation' do
307
+ it 'should be newer than the date of construction' do
308
+ 100.times do
309
+ apartment = DummyApartment.generate
310
+ if apartment.renovated?
311
+ diff = apartment.date_of_renovation - apartment.date_of_construction
312
+ expect(diff).to be >= 0
313
+ end
314
+ end
315
+ end
316
+
317
+ it 'should be consist with #renovated?' do
318
+ 100.times do
319
+ apartment = DummyApartment.generate
320
+ if apartment.renovated?
321
+ expect(apartment.date_of_renovation).to be_a Date
322
+ else
323
+ expect(apartment.date_of_renovation).to be_nil
324
+ end
325
+ end
326
+ end
327
+ end
234
328
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ #-*- coding: utf-8 -*-
2
+
1
3
  lib = File.expand_path('../../lib', __FILE__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
 
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dummy-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-18 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: This gem generates dummy information of apartment, including address,
@@ -60,7 +60,8 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - ".gitignore"
63
+ - .gitignore
64
+ - .travis.yml
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -68,7 +69,6 @@ files:
68
69
  - dummy-apartment.gemspec
69
70
  - lib/data.yml
70
71
  - lib/dummy-apartment.rb
71
- - lib/dummy-apartment/version.rb
72
72
  - spec/data-yml_spec.rb
73
73
  - spec/dummy-apartment_spec.rb
74
74
  - spec/spec_helper.rb
@@ -82,17 +82,17 @@ require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - ">="
85
+ - - '>='
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - ">="
90
+ - - '>='
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.2.0
95
+ rubygems_version: 2.0.14
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Generator of Japanese Apartment Dummy Data
@@ -1,4 +0,0 @@
1
- class DummyApartment
2
- VERSION = "0.1.0"
3
- end
4
-