zonebie 0.0.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -3
- data/README.md +13 -63
- data/lib/zonebie/version.rb +1 -1
- data/lib/zonebie.rb +3 -7
- data/spec/lib/zonebie_spec.rb +3 -10
- data/spec/spec_helper.rb +1 -2
- data/zonebie.gemspec +7 -9
- metadata +109 -147
- data/lib/zonebie/extras/ascii_map.rb +0 -72
- data/lib/zonebie/extras.rb +0 -1
- data/spec/fixtures/ascii_map.png +0 -0
- data/spec/lib/zonebie/extras/ascii_map_spec.rb +0 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 490ab23147f9d6c4f43d468666ad83481dca7289
|
4
|
+
data.tar.gz: aaed4c34a214caff9c5f2616f523dd0ee3cdab38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92afb08fe8ad7fcdb9ffbd0b1209cb6f0673f7edc7f871ca5d3ca9ea9425da55fc63c23ad5f8bbd35192624b08e766f333f299d6a85d3e77a3e808bd5344b64f
|
7
|
+
data.tar.gz: 4d4c6052a63fa47fc108f0e97b2c00ea11d24a2b96142c1597ee3a19b94bbdb651d7b97c07e074ce8fb4063058ab115436276f648967427f7f2cc5061f83533b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
# Zonebie
|
2
2
|
|
3
|
-
[![Build Status](https://secure.travis-ci.org/
|
3
|
+
[![Build Status](https://secure.travis-ci.org/alindeman/zonebie.png)](http://travis-ci.org/alindeman/zonebie)
|
4
4
|
|
5
5
|
Zonebie prevents bugs in code that deals with timezones by randomly assigning a
|
6
6
|
zone on every run.
|
7
7
|
|
8
|
+
If Zonebie helps trigger a timezone-related bug, you can temporarily assign the
|
9
|
+
`ZONEBIE_TZ` environment variable to make your tests deterministic while you
|
10
|
+
debug (more information below).
|
11
|
+
|
8
12
|
## Requirements
|
9
13
|
|
10
|
-
* MRI (1.8.7, 1.9.2, 1.9.3)
|
11
|
-
* JRuby (1.6)
|
14
|
+
* MRI (1.8.7, 1.9.2, 1.9.3, 2.0.0)
|
15
|
+
* JRuby (1.6, 1.7)
|
12
16
|
* Rubinius (1.2, 2.0)
|
13
17
|
|
14
18
|
***
|
15
19
|
|
16
20
|
And **either** of these gems which adds timezone support to Ruby:
|
17
21
|
|
18
|
-
* `activesupport` >= 2.3 (Rails 2.3, 3.0, 3.1, 3.2)
|
22
|
+
* `activesupport` >= 2.3 (Rails 2.3, 3.0, 3.1, 3.2, 4.0)
|
19
23
|
* `tzinfo` >= 0.3
|
20
24
|
|
21
25
|
## Installation
|
@@ -82,76 +86,22 @@ When `Zonebie.set_random_timezone` is called, Zonebie assigns a timezone and
|
|
82
86
|
prints a message to STDOUT:
|
83
87
|
|
84
88
|
```
|
85
|
-
[Zonebie] Setting timezone
|
89
|
+
[Zonebie] Setting timezone: ZONEBIE_TZ="Eastern Time (US & Canada)"
|
86
90
|
```
|
87
91
|
|
88
|
-
If you would rather that Zonebie not print out this information during your
|
89
|
-
put Zonebie in quiet mode before calling `set_random_timezone`:
|
92
|
+
If you would rather that Zonebie not print out this information during your
|
93
|
+
tests, put Zonebie in quiet mode before calling `set_random_timezone`:
|
90
94
|
|
91
95
|
```ruby
|
92
96
|
Zonebie.quiet = true
|
93
97
|
```
|
94
98
|
|
95
99
|
To rerun tests with a specific timezone (e.g., to reproduce a bug that only
|
96
|
-
seems present in one zone), set the `
|
100
|
+
seems present in one zone), set the `ZONEBIE_TZ` environment variable:
|
97
101
|
|
98
102
|
```ruby
|
99
103
|
# Assuming tests run with simply `rake`
|
100
|
-
|
101
|
-
```
|
102
|
-
|
103
|
-
## For the Geographically Impaired
|
104
|
-
|
105
|
-
Zonebie can generate an ASCII map that shows where on the globe your tests are
|
106
|
-
running.
|
107
|
-
|
108
|
-
Note that this makes a request to Google Maps, so it's likely not a good idea
|
109
|
-
to run on each test run :)
|
110
|
-
|
111
|
-
```
|
112
|
-
..... ......
|
113
|
-
..... ........... .
|
114
|
-
. . .. ........... . .
|
115
|
-
. .. .. ........... . ..
|
116
|
-
.. .. . ........ . .......
|
117
|
-
..... .... . ... ....... .. . . ...................
|
118
|
-
............ ........ ... ... .. ..... ...............................
|
119
|
-
... ......... . .. ..... ............................ .
|
120
|
-
........... ... . .. ..................... ......
|
121
|
-
............. ........ .. ...................
|
122
|
-
........... .. . ..... ............... .
|
123
|
-
... . .............. ................
|
124
|
-
... ............. .. .. ... .
|
125
|
-
..... .. .......... . .
|
126
|
-
.......... ...... .
|
127
|
-
....... ..... . .....
|
128
|
-
..... ... .........
|
129
|
-
.... ..
|
130
|
-
..
|
131
|
-
.
|
132
|
-
|
133
|
-
.
|
134
|
-
.. .......... ...................
|
135
|
-
. .... .... ..........................................
|
136
|
-
............... . ............................................
|
137
|
-
.................. . .............................................
|
138
|
-
..................... .............................................
|
139
|
-
.........................................................................
|
140
|
-
...........................................................................
|
141
|
-
```
|
142
|
-
|
143
|
-
Enable the map by setting the `:ascii_map` option to `true`. Again, because it
|
144
|
-
makes an HTTP request, you likely only want to enable it in certain
|
145
|
-
circumstances (e.g., on a CI server or when you explicitly request it):
|
146
|
-
|
147
|
-
```ruby
|
148
|
-
Zonebie.set_random_timezone(:ascii_map => ENV['CI'] || ENV['MAP'])
|
149
|
-
```
|
150
|
-
|
151
|
-
And run with:
|
152
|
-
|
153
|
-
```ruby
|
154
|
-
MAP=1 rake
|
104
|
+
ZONEBIE_TZ="Eastern Time (US & Canada)" rake
|
155
105
|
```
|
156
106
|
|
157
107
|
## Contributing
|
data/lib/zonebie/version.rb
CHANGED
data/lib/zonebie.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.expand_path("zonebie/version", File.dirname(__FILE__))
|
2
|
-
require File.expand_path("zonebie/extras", File.dirname(__FILE__))
|
3
2
|
|
4
3
|
module Zonebie
|
5
4
|
class << self
|
@@ -37,13 +36,10 @@ module Zonebie
|
|
37
36
|
@backends[backend.name] = backend
|
38
37
|
end
|
39
38
|
|
40
|
-
def set_random_timezone
|
41
|
-
zone = ENV['
|
39
|
+
def set_random_timezone
|
40
|
+
zone = ENV['ZONEBIE_TZ'] || random_timezone
|
42
41
|
|
43
|
-
unless quiet
|
44
|
-
$stdout.puts("[Zonebie] Setting timezone to \"#{zone}\"")
|
45
|
-
$stdout.puts(Zonebie::Extras::AsciiMap.new(zone).to_s) if options[:ascii_map]
|
46
|
-
end
|
42
|
+
$stdout.puts("[Zonebie] Setting timezone: ZONEBIE_TZ=\"#{zone}\"") unless quiet
|
47
43
|
backend.zone = zone
|
48
44
|
end
|
49
45
|
|
data/spec/lib/zonebie_spec.rb
CHANGED
@@ -54,17 +54,10 @@ describe Zonebie do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "outputs the timezone to STDOUT" do
|
57
|
-
$stdout.expects(:puts).with("[Zonebie] Setting timezone
|
57
|
+
$stdout.expects(:puts).with("[Zonebie] Setting timezone: ZONEBIE_TZ=\"Eastern Time (US & Canada)\"")
|
58
58
|
Zonebie.set_random_timezone
|
59
59
|
end
|
60
60
|
|
61
|
-
it "outputs the ascii map to STDOUT if the option is present" do
|
62
|
-
Zonebie::Extras::AsciiMap.any_instance.stubs(:to_s).returns('ascii map')
|
63
|
-
$stdout.expects(:puts).with("[Zonebie] Setting timezone to \"Eastern Time (US & Canada)\"")
|
64
|
-
$stdout.expects(:puts).with('ascii map')
|
65
|
-
Zonebie.set_random_timezone(:ascii_map => true)
|
66
|
-
end
|
67
|
-
|
68
61
|
it "does not output the timezone to STDOUT if quiet mode is enabled" do
|
69
62
|
$stdout.expects(:puts).never
|
70
63
|
|
@@ -76,12 +69,12 @@ describe Zonebie do
|
|
76
69
|
end
|
77
70
|
end
|
78
71
|
|
79
|
-
it "sends the timezone as ENV[
|
72
|
+
it "sends the timezone as ENV[ZONEBIE_TZ] if present" do
|
80
73
|
$stdout.stubs(:puts)
|
81
74
|
|
82
75
|
backend.expects(:zone=).with("Pacific Time (US & Canada)")
|
83
76
|
|
84
|
-
ENV['
|
77
|
+
ENV['ZONEBIE_TZ'] = "Pacific Time (US & Canada)"
|
85
78
|
Zonebie.set_random_timezone
|
86
79
|
end
|
87
80
|
end
|
data/spec/spec_helper.rb
CHANGED
data/zonebie.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
require File.expand_path('../lib/zonebie/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
5
|
+
gem.authors = ['Andy Lindeman', 'Steven Harman', 'Patrick Van Stee']
|
6
|
+
gem.email = ['andy@andylindeman.com', 'steveharman@gmail.com', 'patrickvanstee@gmail.com']
|
7
7
|
gem.description = %q{Runs your tests in a random timezone}
|
8
8
|
gem.summary = %q{Zonebie prevents bugs in code that deals with timezones by randomly assigning a zone on every run}
|
9
|
-
gem.homepage = "https://github.com/
|
9
|
+
gem.homepage = "https://github.com/alindeman/zonebie"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
@@ -16,12 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = Zonebie::VERSION
|
17
17
|
|
18
18
|
gem.add_development_dependency "rake"
|
19
|
-
gem.add_development_dependency "rspec", "~>2.
|
20
|
-
gem.add_development_dependency "mocha", "~>0.
|
19
|
+
gem.add_development_dependency "rspec", "~>2.14"
|
20
|
+
gem.add_development_dependency "mocha", "~>0.14.0"
|
21
21
|
|
22
22
|
gem.add_development_dependency "activesupport", ">=2.3"
|
23
|
-
gem.add_development_dependency "tzinfo", ">=0.
|
24
|
-
|
25
|
-
gem.add_dependency "chunky_png"
|
26
|
-
gem.add_dependency "rainbow"
|
23
|
+
gem.add_development_dependency "tzinfo", "~>1.0", ">= 1.0.1"
|
24
|
+
gem.add_development_dependency "tzinfo-data", ">= 1.2013.4"
|
27
25
|
end
|
metadata
CHANGED
@@ -1,135 +1,116 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: zonebie
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Andy Lindeman
|
8
|
+
- Steven Harman
|
9
|
+
- Patrick Van Stee
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
31
|
-
requirement: *id001
|
32
|
-
type: :development
|
13
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
33
16
|
name: rake
|
34
|
-
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
35
23
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rspec
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
39
33
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
segments:
|
43
|
-
- 2
|
44
|
-
- 8
|
45
|
-
version: "2.8"
|
46
|
-
requirement: *id002
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '2.14'
|
47
36
|
type: :development
|
48
|
-
name: rspec
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
37
|
prerelease: false
|
51
|
-
version_requirements:
|
52
|
-
|
53
|
-
requirements:
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
54
40
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
- 10
|
60
|
-
- 0
|
61
|
-
version: 0.10.0
|
62
|
-
requirement: *id003
|
63
|
-
type: :development
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.14'
|
43
|
+
- !ruby/object:Gem::Dependency
|
64
44
|
name: mocha
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
hash: 5
|
73
|
-
segments:
|
74
|
-
- 2
|
75
|
-
- 3
|
76
|
-
version: "2.3"
|
77
|
-
requirement: *id004
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.14.0
|
78
50
|
type: :development
|
79
|
-
name: activesupport
|
80
|
-
- !ruby/object:Gem::Dependency
|
81
51
|
prerelease: false
|
82
|
-
version_requirements:
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.14.0
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: activesupport
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.3'
|
93
64
|
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.3'
|
71
|
+
- !ruby/object:Gem::Dependency
|
94
72
|
name: tzinfo
|
95
|
-
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.0'
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.0.1
|
81
|
+
type: :development
|
96
82
|
prerelease: false
|
97
|
-
version_requirements:
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
-
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.0'
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.0.1
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: tzinfo-data
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.2013.4
|
98
|
+
type: :development
|
110
99
|
prerelease: false
|
111
|
-
version_requirements:
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
hash: 3
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
version: "0"
|
120
|
-
requirement: *id007
|
121
|
-
type: :runtime
|
122
|
-
name: rainbow
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.2013.4
|
123
105
|
description: Runs your tests in a random timezone
|
124
|
-
email:
|
125
|
-
-
|
106
|
+
email:
|
107
|
+
- andy@andylindeman.com
|
108
|
+
- steveharman@gmail.com
|
109
|
+
- patrickvanstee@gmail.com
|
126
110
|
executables: []
|
127
|
-
|
128
111
|
extensions: []
|
129
|
-
|
130
112
|
extra_rdoc_files: []
|
131
|
-
|
132
|
-
files:
|
113
|
+
files:
|
133
114
|
- .gitignore
|
134
115
|
- .travis.yml
|
135
116
|
- Gemfile
|
@@ -140,56 +121,37 @@ files:
|
|
140
121
|
- lib/zonebie/backends.rb
|
141
122
|
- lib/zonebie/backends/active_support.rb
|
142
123
|
- lib/zonebie/backends/tzinfo.rb
|
143
|
-
- lib/zonebie/extras.rb
|
144
|
-
- lib/zonebie/extras/ascii_map.rb
|
145
124
|
- lib/zonebie/rspec.rb
|
146
125
|
- lib/zonebie/version.rb
|
147
|
-
- spec/fixtures/ascii_map.png
|
148
126
|
- spec/integrations/activesupport_spec.rb
|
149
127
|
- spec/lib/zonebie/backends/active_support_spec.rb
|
150
128
|
- spec/lib/zonebie/backends/tzinfo_spec.rb
|
151
|
-
- spec/lib/zonebie/extras/ascii_map_spec.rb
|
152
129
|
- spec/lib/zonebie_spec.rb
|
153
130
|
- spec/spec_helper.rb
|
154
131
|
- zonebie.gemspec
|
155
|
-
homepage: https://github.com/
|
132
|
+
homepage: https://github.com/alindeman/zonebie
|
156
133
|
licenses: []
|
157
|
-
|
134
|
+
metadata: {}
|
158
135
|
post_install_message:
|
159
136
|
rdoc_options: []
|
160
|
-
|
161
|
-
require_paths:
|
137
|
+
require_paths:
|
162
138
|
- lib
|
163
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
none: false
|
174
|
-
requirements:
|
175
|
-
- - ">="
|
176
|
-
- !ruby/object:Gem::Version
|
177
|
-
hash: 3
|
178
|
-
segments:
|
179
|
-
- 0
|
180
|
-
version: "0"
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
181
149
|
requirements: []
|
182
|
-
|
183
150
|
rubyforge_project:
|
184
|
-
rubygems_version:
|
151
|
+
rubygems_version: 2.0.3
|
185
152
|
signing_key:
|
186
|
-
specification_version:
|
187
|
-
summary: Zonebie prevents bugs in code that deals with timezones by randomly assigning
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
- spec/lib/zonebie/backends/active_support_spec.rb
|
192
|
-
- spec/lib/zonebie/backends/tzinfo_spec.rb
|
193
|
-
- spec/lib/zonebie/extras/ascii_map_spec.rb
|
194
|
-
- spec/lib/zonebie_spec.rb
|
195
|
-
- spec/spec_helper.rb
|
153
|
+
specification_version: 4
|
154
|
+
summary: Zonebie prevents bugs in code that deals with timezones by randomly assigning
|
155
|
+
a zone on every run
|
156
|
+
test_files: []
|
157
|
+
has_rdoc:
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'open-uri'
|
3
|
-
require 'chunky_png'
|
4
|
-
require 'rainbow'
|
5
|
-
|
6
|
-
Sickill::Rainbow.enabled = true
|
7
|
-
|
8
|
-
module Zonebie
|
9
|
-
module Extras
|
10
|
-
class AsciiMap
|
11
|
-
attr_accessor :zone, :image, :ascii, :mark
|
12
|
-
|
13
|
-
def initialize(zone)
|
14
|
-
self.zone = zone
|
15
|
-
self.mark = false
|
16
|
-
self.ascii = map_to_ascii
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
ascii
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def disable_webmock
|
26
|
-
if defined? WebMock
|
27
|
-
allow_net_connect_was = WebMock::Config.instance.allow_net_connect
|
28
|
-
WebMock::Config.instance.allow_net_connect = true
|
29
|
-
yield
|
30
|
-
WebMock::Config.instance.allow_net_connect = allow_net_connect_was
|
31
|
-
else
|
32
|
-
yield
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def google_maps_request
|
37
|
-
"http://maps.googleapis.com/maps/api/staticmap?format=png8&zoom=1&maptype=roadmap&sensor=false¢er=0,0&size=500x500&markers=size:large%7Ccolor:red%7C#{URI.encode(zone)}&style=feature:all%7Celement:labels%7Cvisibility:off&style=feature:all%7Celement:geometry%7Clightness:100&style=feature:water%7Celement:geometry%7Clightness:-100"
|
38
|
-
end
|
39
|
-
|
40
|
-
def map_to_ascii
|
41
|
-
image = nil
|
42
|
-
|
43
|
-
disable_webmock do
|
44
|
-
open google_maps_request do |f|
|
45
|
-
image = ChunkyPNG::Image.from_blob(f.read)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
image.resample_nearest_neighbor!(80, 30)
|
50
|
-
dots = image.pixels.map{ |p| colored_dot(p) }
|
51
|
-
dots.each_slice(80).map{ |d| d.join }.join("\n")
|
52
|
-
end
|
53
|
-
|
54
|
-
def colored_dot(color)
|
55
|
-
if ChunkyPNG::Color.grayscale? color
|
56
|
-
if ChunkyPNG::Color.r(color) > (255 / 2)
|
57
|
-
'.'
|
58
|
-
else
|
59
|
-
' '
|
60
|
-
end
|
61
|
-
else
|
62
|
-
if mark
|
63
|
-
'.'
|
64
|
-
else
|
65
|
-
self.mark = true
|
66
|
-
'X'.color(:red)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/lib/zonebie/extras.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.expand_path("extras/ascii_map", File.dirname(__FILE__))
|
data/spec/fixtures/ascii_map.png
DELETED
Binary file
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Zonebie::Extras::AsciiMap do
|
4
|
-
describe "#to_s" do
|
5
|
-
it "prints a map of the world" do
|
6
|
-
map = File.open(File.expand_path('../../../fixtures/ascii_map.png', File.dirname(__FILE__)))
|
7
|
-
Zonebie::Extras::AsciiMap.any_instance.expects(:open).yields(map)
|
8
|
-
|
9
|
-
Zonebie::Extras::AsciiMap.new('International Date Line West').to_s.should ==
|
10
|
-
%{
|
11
|
-
..... ......
|
12
|
-
..... ........... .
|
13
|
-
. . .. ........... . .
|
14
|
-
. .. .. ........... . ..
|
15
|
-
.. .. . ........ . .......
|
16
|
-
..... .... . ... ....... .. . . ...................
|
17
|
-
............ ........ ... ... .. ..... ...............................
|
18
|
-
... ......... . .. ..... ............................ .
|
19
|
-
........... \e[31mX\e[0m.. . .. ..................... ......
|
20
|
-
............ ........ .. ...................
|
21
|
-
........... .. . ..... ............... .
|
22
|
-
... . .............. ................
|
23
|
-
... ............. .. .. ... .
|
24
|
-
..... .. .......... . .
|
25
|
-
.......... ...... .
|
26
|
-
....... ..... . .....
|
27
|
-
..... ... .........
|
28
|
-
.... ..
|
29
|
-
..
|
30
|
-
.
|
31
|
-
|
32
|
-
.
|
33
|
-
.. .......... ...................
|
34
|
-
. .... .... ..........................................
|
35
|
-
............... . ............................................
|
36
|
-
.................. . .............................................
|
37
|
-
..................... .............................................
|
38
|
-
.........................................................................
|
39
|
-
...........................................................................}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|