machiawase 0.5.0 → 0.6.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 +4 -4
- data/Guardfile +6 -6
- data/bin/machiawase +2 -2
- data/lib/machiawase.rb +3 -75
- data/lib/machiawase/place.rb +20 -24
- data/lib/machiawase/rendezvous.rb +84 -0
- data/lib/machiawase/version.rb +1 -1
- data/machiawase.gemspec +1 -0
- data/test/machiawase/test_place.rb +43 -0
- data/test/machiawase/test_rendezvous.rb +38 -0
- data/test/test_helper.rb +7 -0
- data/test/test_machiawase.rb +9 -0
- metadata +27 -9
- data/spec/machiawase/place_spec.rb +0 -86
- data/spec/machiawase_spec.rb +0 -60
- data/spec/spec_helper.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c80da4652173863278773783be83df5ea717c53f
|
4
|
+
data.tar.gz: 51cdbb0c5f81b146ce85954ae8fb53138f6e12c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 678b67366bc00e9e2ca369053f40a250da88035fdd541190e61532d1abbf8c78f1c2d45da8e978400051f2a0877c7c596997328e29c274385c136ba3fd50cbc6
|
7
|
+
data.tar.gz: fd98d9e570ddc1bc059b48f32bc9cede4b95cf036b49396c0e9ca69809ec02f1cb8eccde79345196750d43cc4d2e0f069347b3fe40d7bb579e818a53df9178e5
|
data/Guardfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
guard 'minitest' do
|
2
2
|
# with Minitest::Unit
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
watch(%r|^test/(.*)\/?test_(.*)\.rb|)
|
4
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
5
|
+
watch(%r|^test/test_helper\.rb|) { "test" }
|
6
6
|
|
7
7
|
# with Minitest::Spec
|
8
|
-
watch(%r|^spec/(.*)_spec\.rb|)
|
9
|
-
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
10
|
-
watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
8
|
+
# watch(%r|^spec/(.*)_spec\.rb|)
|
9
|
+
# watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
10
|
+
# watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
11
11
|
|
12
12
|
# Rails 3.2
|
13
13
|
# watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
|
data/bin/machiawase
CHANGED
@@ -14,9 +14,9 @@ opt_parser = OptionParser.new do |opts|
|
|
14
14
|
opts.separator ""
|
15
15
|
opts.separator "Specific options:"
|
16
16
|
|
17
|
-
opts.on('-a', '--all', 'Show all informations of the result with JSON format')
|
17
|
+
opts.on('-a', '--all', 'Show all informations of the result with JSON format') do
|
18
18
|
options.show_all = true
|
19
|
-
|
19
|
+
end
|
20
20
|
|
21
21
|
opts.separator ""
|
22
22
|
opts.separator "Common options:"
|
data/lib/machiawase.rb
CHANGED
@@ -2,9 +2,12 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
|
+
require 'msgpack'
|
5
6
|
require 'nokogiri'
|
6
7
|
require 'open-uri'
|
8
|
+
require 'ostruct'
|
7
9
|
require 'machiawase/place'
|
10
|
+
require 'machiawase/rendezvous'
|
8
11
|
require 'machiawase/version'
|
9
12
|
|
10
13
|
# @author {https://github.com/zakuni zakuni}
|
@@ -21,79 +24,4 @@ module Machiawase
|
|
21
24
|
m = Rendezvous.new(*places)
|
22
25
|
m.place
|
23
26
|
end
|
24
|
-
|
25
|
-
class Rendezvous
|
26
|
-
# @!attribute [r] place
|
27
|
-
# @return [Place] the place to rendezvous.
|
28
|
-
# @!attribute [r] places
|
29
|
-
# @return [Array<Place>] the array of given places.
|
30
|
-
# @see Place
|
31
|
-
|
32
|
-
attr_reader :place, :places, :lat, :lon, :address, :near_station
|
33
|
-
|
34
|
-
# @param places [Array<Place>] the array of places.
|
35
|
-
def initialize(*places)
|
36
|
-
@place = nil
|
37
|
-
@places = places
|
38
|
-
end
|
39
|
-
|
40
|
-
def place
|
41
|
-
@place ||= middle_of(*@places)
|
42
|
-
end
|
43
|
-
|
44
|
-
def lat
|
45
|
-
@place ||= middle_of(*@places)
|
46
|
-
@place.lat
|
47
|
-
end
|
48
|
-
|
49
|
-
def lon
|
50
|
-
@place ||= middle_of(*@places)
|
51
|
-
@place.lon
|
52
|
-
end
|
53
|
-
|
54
|
-
def address
|
55
|
-
@place ||= middle_of(*@places)
|
56
|
-
@place.address
|
57
|
-
end
|
58
|
-
|
59
|
-
def near_station
|
60
|
-
@place ||= middle_of(*@places)
|
61
|
-
@place.near_station
|
62
|
-
end
|
63
|
-
|
64
|
-
# @return [Hash] the attributes with Hash format.
|
65
|
-
def to_h
|
66
|
-
h = Hash.new
|
67
|
-
@places.each_with_index do |place, i|
|
68
|
-
h.store("place#{i}", place.to_h)
|
69
|
-
end
|
70
|
-
|
71
|
-
@place ||= middle_of(*@places)
|
72
|
-
h.store("machiawase", @place.to_h)
|
73
|
-
end
|
74
|
-
|
75
|
-
# @return [JSON] the attributes with JSON format.
|
76
|
-
def to_json
|
77
|
-
JSON.pretty_generate(to_h)
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def middle_of(*places)
|
83
|
-
c = centroid(*places)
|
84
|
-
@place = Place.new(c[0], c[1])
|
85
|
-
end
|
86
|
-
|
87
|
-
def centroid(*places)
|
88
|
-
x_sum = 0
|
89
|
-
y_sum = 0
|
90
|
-
|
91
|
-
places.each do |p|
|
92
|
-
x_sum += p.lat
|
93
|
-
y_sum += p.lon
|
94
|
-
end
|
95
|
-
|
96
|
-
[x_sum/places.length.to_f, y_sum/places.length.to_f]
|
97
|
-
end
|
98
|
-
end
|
99
27
|
end
|
data/lib/machiawase/place.rb
CHANGED
@@ -41,12 +41,11 @@ module Machiawase
|
|
41
41
|
|
42
42
|
# @return [Hash] geocode of given address.
|
43
43
|
def self.geocode(address)
|
44
|
-
address = URI.encode(address)
|
45
44
|
baseUrl = "http://maps.google.com/maps/api/geocode/json"
|
46
|
-
reqUrl = "#{baseUrl}?address=#{address}&sensor=false&language=ja"
|
45
|
+
reqUrl = "#{baseUrl}?address=#{URI.encode(address)}&sensor=false&language=ja"
|
47
46
|
proxy = parse_proxy(ENV["http_proxy"])
|
48
|
-
response =
|
49
|
-
status = JSON.parse(response.
|
47
|
+
response = open(URI.parse(reqUrl), :proxy_http_basic_authentication => [proxy.server, proxy.user, proxy.pass])
|
48
|
+
status = JSON.parse(response.string)
|
50
49
|
lat = status['results'][0]['geometry']['location']['lat']
|
51
50
|
lon = status['results'][0]['geometry']['location']['lng']
|
52
51
|
{"lat" => lat, "lon" => lon}
|
@@ -61,32 +60,25 @@ module Machiawase
|
|
61
60
|
account = raccount.nil? ? "" : raccount.reverse.split(":")
|
62
61
|
user, pass = account
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
"user" => user.nil? ? "" : user,
|
70
|
-
"pass" => pass.nil? ? "" : pass
|
71
|
-
}
|
63
|
+
proxy = OpenStruct.new({
|
64
|
+
"server" => server.empty? ? nil : "http://#{server}",
|
65
|
+
"user" => user.nil? ? "" : user,
|
66
|
+
"pass" => pass.nil? ? "" : pass
|
67
|
+
})
|
72
68
|
end
|
73
69
|
|
74
70
|
def address
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
"Service Temporary Unavailable"
|
80
|
-
end
|
71
|
+
@doc ||= Nokogiri::HTML(open("http://geocode.didit.jp/reverse/?lat=#{@lat}&lon=#{@lon}", :proxy_http_basic_authentication => [@proxy.server, @proxy.user, @proxy.pass]))
|
72
|
+
@address ||= @doc.xpath('//address')[0].content
|
73
|
+
rescue => exc
|
74
|
+
p exc
|
81
75
|
end
|
82
76
|
|
83
77
|
def near_station
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
"Service Temporary Unavailable"
|
89
|
-
end
|
78
|
+
@doc ||= Nokogiri::HTML(open("http://geocode.didit.jp/reverse/?lat=#{@lat}&lon=#{@lon}", :proxy_http_basic_authentication => [@proxy.server, @proxy.user, @proxy.pass]))
|
79
|
+
@near_station ||= @doc.xpath('//station1')[0].content
|
80
|
+
rescue => exc
|
81
|
+
p exc
|
90
82
|
end
|
91
83
|
|
92
84
|
# @return [Hash] attributes with Hash format.
|
@@ -104,5 +96,9 @@ module Machiawase
|
|
104
96
|
def to_json
|
105
97
|
JSON.pretty_generate(to_h)
|
106
98
|
end
|
99
|
+
|
100
|
+
def to_msgpack
|
101
|
+
to_h.to_msgpack
|
102
|
+
end
|
107
103
|
end
|
108
104
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
module Machiawase
|
5
|
+
|
6
|
+
class Rendezvous
|
7
|
+
# @!attribute [r] place
|
8
|
+
# @return [Place] the place to rendezvous.
|
9
|
+
# @!attribute [r] places
|
10
|
+
# @return [Array<Place>] the array of given places.
|
11
|
+
# @see Place
|
12
|
+
|
13
|
+
attr_reader :place, :places, :lat, :lon, :address, :near_station
|
14
|
+
|
15
|
+
# @param places [Array<Place>] the array of places.
|
16
|
+
def initialize(*places)
|
17
|
+
@place = nil
|
18
|
+
@places = places
|
19
|
+
end
|
20
|
+
|
21
|
+
def place
|
22
|
+
@place ||= middle_of(*@places)
|
23
|
+
end
|
24
|
+
|
25
|
+
def lat
|
26
|
+
@place ||= middle_of(*@places)
|
27
|
+
@place.lat
|
28
|
+
end
|
29
|
+
|
30
|
+
def lon
|
31
|
+
@place ||= middle_of(*@places)
|
32
|
+
@place.lon
|
33
|
+
end
|
34
|
+
|
35
|
+
def address
|
36
|
+
@place ||= middle_of(*@places)
|
37
|
+
@place.address
|
38
|
+
end
|
39
|
+
|
40
|
+
def near_station
|
41
|
+
@place ||= middle_of(*@places)
|
42
|
+
@place.near_station
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Hash] the attributes with Hash format.
|
46
|
+
def to_h
|
47
|
+
h = Hash.new
|
48
|
+
@places.each_with_index do |place, i|
|
49
|
+
h.store("place#{i}", place.to_h)
|
50
|
+
end
|
51
|
+
|
52
|
+
@place ||= middle_of(*@places)
|
53
|
+
h.store("machiawase", @place.to_h)
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [JSON] the attributes with JSON format.
|
57
|
+
def to_json
|
58
|
+
JSON.pretty_generate(to_h)
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_msgpack
|
62
|
+
to_h.to_msgpack
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def middle_of(*places)
|
68
|
+
c = centroid(*places)
|
69
|
+
@place = Place.new(c[0], c[1])
|
70
|
+
end
|
71
|
+
|
72
|
+
def centroid(*places)
|
73
|
+
x_sum = 0
|
74
|
+
y_sum = 0
|
75
|
+
|
76
|
+
places.each do |p|
|
77
|
+
x_sum += p.lat
|
78
|
+
y_sum += p.lon
|
79
|
+
end
|
80
|
+
|
81
|
+
[x_sum/places.length.to_f, y_sum/places.length.to_f]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/machiawase/version.rb
CHANGED
data/machiawase.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = Machiawase::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency "nokogiri"
|
19
|
+
gem.add_dependency "msgpack"
|
19
20
|
gem.add_development_dependency "guard-minitest"
|
20
21
|
gem.add_development_dependency "rb-fsevent"
|
21
22
|
gem.add_development_dependency "minitest-reporters"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class TestPlace < MiniTest::Unit::TestCase
|
6
|
+
include Machiawase
|
7
|
+
|
8
|
+
def test_address
|
9
|
+
assert_equal Place.new(35.4437078, 139.6380256).address, "神奈川県横浜市中区真砂町1丁目9"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_geocode
|
13
|
+
assert_equal({"lat" => 35.4437078, "lon" => 139.6380256}, Place.geocode('横浜'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_near_station
|
17
|
+
assert_equal Place.new(35.4437978, 139.6380256).near_station, "関内駅"
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_parse_proxy
|
21
|
+
assert_respond_to Place, :parse_proxy
|
22
|
+
|
23
|
+
return_with_nil = Place.parse_proxy(nil)
|
24
|
+
assert_kind_of OpenStruct, return_with_nil
|
25
|
+
assert_respond_to return_with_nil, :user
|
26
|
+
assert_respond_to return_with_nil, :pass
|
27
|
+
|
28
|
+
assert_equal(OpenStruct.new({"server" => "http://host:port",
|
29
|
+
"user" => "user",
|
30
|
+
"pass" => "pass"}),
|
31
|
+
Place.parse_proxy("user:pass@host:port"))
|
32
|
+
|
33
|
+
assert_equal(OpenStruct.new({"server" => "http://host:port",
|
34
|
+
"user" => "",
|
35
|
+
"pass" => ""}),
|
36
|
+
Place.parse_proxy("host:port"))
|
37
|
+
|
38
|
+
assert_equal(OpenStruct.new({"server" => nil,
|
39
|
+
"user" => "",
|
40
|
+
"pass" => ""}),
|
41
|
+
Place.parse_proxy(nil))
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class TestRendezvous < MiniTest::Unit::TestCase
|
6
|
+
include Machiawase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@rendezvous = Rendezvous.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_centroid
|
13
|
+
place_a = Place.new(0, 0)
|
14
|
+
place_b = Place.new(1, 1)
|
15
|
+
assert_equal [0.5, 0.5], @rendezvous.send(:centroid, *[place_a, place_b])
|
16
|
+
|
17
|
+
place_a = Place.new(0, 0)
|
18
|
+
place_b = Place.new(1, 1)
|
19
|
+
place_c = Machiawase::Place.new(2, 2)
|
20
|
+
assert_equal [1, 1], @rendezvous.send(:centroid, *[place_a, place_b, place_c])
|
21
|
+
|
22
|
+
place_a = Place.new(0, 0)
|
23
|
+
place_b = Place.new(2, 0)
|
24
|
+
place_c = Place.new(2, 2)
|
25
|
+
place_d = Place.new(0, 2)
|
26
|
+
assert_equal [1, 1], @rendezvous.send(:centroid, *[place_a, place_b, place_c, place_d])
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_middle_of
|
30
|
+
g1 = Place.geocode("横浜")
|
31
|
+
p1 = Place.new(g1['lat'], g1['lon'])
|
32
|
+
|
33
|
+
g2 = Place.geocode("東京")
|
34
|
+
p2 = Place.new(g2['lat'], g2['lon'])
|
35
|
+
|
36
|
+
assert_kind_of Place, @rendezvous.send(:middle_of, p1, p2)
|
37
|
+
end
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: machiawase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zakuni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: msgpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: guard-minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,11 +112,13 @@ files:
|
|
98
112
|
- bin/machiawase
|
99
113
|
- lib/machiawase.rb
|
100
114
|
- lib/machiawase/place.rb
|
115
|
+
- lib/machiawase/rendezvous.rb
|
101
116
|
- lib/machiawase/version.rb
|
102
117
|
- machiawase.gemspec
|
103
|
-
-
|
104
|
-
-
|
105
|
-
-
|
118
|
+
- test/machiawase/test_place.rb
|
119
|
+
- test/machiawase/test_rendezvous.rb
|
120
|
+
- test/test_helper.rb
|
121
|
+
- test/test_machiawase.rb
|
106
122
|
homepage: http://zakuni.github.com/machiawase/
|
107
123
|
licenses: []
|
108
124
|
metadata: {}
|
@@ -122,11 +138,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
138
|
version: '0'
|
123
139
|
requirements: []
|
124
140
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.0.
|
141
|
+
rubygems_version: 2.0.2
|
126
142
|
signing_key:
|
127
143
|
specification_version: 4
|
128
144
|
summary: finds a middle point of plural points
|
129
145
|
test_files:
|
130
|
-
-
|
131
|
-
-
|
132
|
-
-
|
146
|
+
- test/machiawase/test_place.rb
|
147
|
+
- test/machiawase/test_rendezvous.rb
|
148
|
+
- test/test_helper.rb
|
149
|
+
- test/test_machiawase.rb
|
150
|
+
has_rdoc:
|
@@ -1,86 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Machiawase::Place do
|
6
|
-
describe ':address' do
|
7
|
-
it 'returns 神奈川県横浜市中区真砂町1丁目9 with "35.4437078, 139.6380256"' do
|
8
|
-
Machiawase::Place.new(35.4437078, 139.6380256).address.must_equal("神奈川県横浜市中区真砂町1丁目9")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'geocode' do
|
13
|
-
it 'returns {lat => 35.4437978, lon => 139.6380256} with 横浜' do
|
14
|
-
Machiawase::Place.geocode('横浜').must_equal({"lat" => 35.4437078, "lon" => 139.6380256})
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'near_station' do
|
19
|
-
it 'returns 関内駅 with 横浜' do
|
20
|
-
Machiawase::Place.new(35.4437978, 139.6380256).near_station.must_equal("関内駅")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "parse_proxy" do
|
25
|
-
it 'responds' do
|
26
|
-
Machiawase::Place.must_respond_to("parse_proxy")
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns Hash' do
|
30
|
-
Machiawase::Place.parse_proxy(nil).must_be_kind_of(Hash)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'includes "host"' do
|
34
|
-
Machiawase::Place.parse_proxy(nil).must_include("host")
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'includes "port"' do
|
38
|
-
Machiawase::Place.parse_proxy(nil).must_include("port")
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'includes "user"' do
|
42
|
-
Machiawase::Place.parse_proxy(nil).must_include("user")
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'includes "pass"' do
|
46
|
-
Machiawase::Place.parse_proxy(nil).must_include("pass")
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns correct hash with "user:pass@host:port"' do
|
50
|
-
Machiawase::Place.parse_proxy(
|
51
|
-
"user:pass@host:port"
|
52
|
-
).must_equal({
|
53
|
-
"server" => "http://host:port",
|
54
|
-
"host" => "host",
|
55
|
-
"port" => "port",
|
56
|
-
"user" => "user",
|
57
|
-
"pass" => "pass"
|
58
|
-
})
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'returns correct hash with "host:port"' do
|
62
|
-
Machiawase::Place.parse_proxy(
|
63
|
-
"host:port"
|
64
|
-
).must_equal({
|
65
|
-
"server" => "http://host:port",
|
66
|
-
|
67
|
-
"host" => "host",
|
68
|
-
"port" => "port",
|
69
|
-
"user" => "",
|
70
|
-
"pass" => ""
|
71
|
-
})
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'returns correct hash with nil' do
|
75
|
-
Machiawase::Place.parse_proxy(nil).must_equal(
|
76
|
-
{
|
77
|
-
"server" => nil,
|
78
|
-
"host" => nil,
|
79
|
-
"port" => nil,
|
80
|
-
"user" => "",
|
81
|
-
"pass" => ""
|
82
|
-
})
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
data/spec/machiawase_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Machiawase do
|
6
|
-
describe 'where' do
|
7
|
-
describe '横浜, 東京' do
|
8
|
-
it 'should be Place' do
|
9
|
-
Machiawase.where("横浜", "東京").class.must_equal(Machiawase::Place)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe Machiawase::Rendezvous do
|
16
|
-
before do
|
17
|
-
@machiawase = Machiawase::Rendezvous.new
|
18
|
-
end
|
19
|
-
|
20
|
-
describe ":centroid" do
|
21
|
-
describe '(0, 0), (1, 1)' do
|
22
|
-
it 'should be (0.5, 0.5)' do
|
23
|
-
place_a = Machiawase::Place.new(0, 0)
|
24
|
-
place_b = Machiawase::Place.new(1, 1)
|
25
|
-
@machiawase.send(:centroid, *[place_a, place_b]).must_equal([0.5, 0.5])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
describe '(0, 0), (1, 1), (2, 2)' do
|
29
|
-
it 'should be (1, 1)' do
|
30
|
-
place_a = Machiawase::Place.new(0, 0)
|
31
|
-
place_b = Machiawase::Place.new(1, 1)
|
32
|
-
place_c = Machiawase::Place.new(2, 2)
|
33
|
-
@machiawase.send(:centroid, *[place_a, place_b, place_c]).must_equal([1, 1])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
describe '(0, 0), (2, 0), (2, 2), (0, 2)' do
|
37
|
-
it 'should be (1, 1)' do
|
38
|
-
place_a = Machiawase::Place.new(0, 0)
|
39
|
-
place_b = Machiawase::Place.new(2, 0)
|
40
|
-
place_c = Machiawase::Place.new(2, 2)
|
41
|
-
place_d = Machiawase::Place.new(0, 2)
|
42
|
-
@machiawase.send(:centroid, *[place_a, place_b, place_c, place_d]).must_equal([1, 1])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe ':middle_of' do
|
48
|
-
describe '横浜, 東京' do
|
49
|
-
it 'should be Place' do
|
50
|
-
g1 = Machiawase::Place.geocode("横浜")
|
51
|
-
p1 = Machiawase::Place.new(g1['lat'], g1['lon'])
|
52
|
-
|
53
|
-
g2 = Machiawase::Place.geocode("東京")
|
54
|
-
p2 = Machiawase::Place.new(g2['lat'], g2['lon'])
|
55
|
-
|
56
|
-
@machiawase.send(:middle_of, p1, p2).class.must_equal(Machiawase::Place)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|