machiawase 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +9 -0
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/autotest/discover.rb +3 -0
- data/bin/machiawase +8 -0
- data/lib/machiawase.rb +68 -0
- data/lib/machiawase/version.rb +3 -0
- data/machiawase.gemspec +22 -0
- data/spec/machiawase_spec.rb +60 -0
- metadata +106 -0
data/.autotest
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Autotest.add_hook(:initialize) {|at|
|
2
|
+
at.add_exception %r{^\.git} # ignore Version Control System
|
3
|
+
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
|
4
|
+
# at.clear_mappings #take out the default (test/test*rb)
|
5
|
+
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
|
6
|
+
Dir['spec/**/*_spec.rb']
|
7
|
+
}
|
8
|
+
nil
|
9
|
+
}
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 zakuni
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Machiawase
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'machiawase'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install machiawase
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
$ machiawase PLACE_A PLACE_B
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/machiawase
ADDED
data/lib/machiawase.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'machiawase/version'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
require 'hpricot'
|
7
|
+
require 'open-uri'
|
8
|
+
|
9
|
+
class Machiawase
|
10
|
+
def middle_of(*spots)
|
11
|
+
@coordinates = Array.new
|
12
|
+
|
13
|
+
spots.each do |spot|
|
14
|
+
lat_lng = geocode(spot)
|
15
|
+
@coordinates.push(Coordinates.new(lat_lng[0], lat_lng[1]))
|
16
|
+
end
|
17
|
+
|
18
|
+
lat_lon = centroid(*@coordinates)
|
19
|
+
place_name(lat_lon[0], lat_lon[1])
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def geocode(address)
|
26
|
+
address = URI.encode(address)
|
27
|
+
hash = Hash.new
|
28
|
+
baseUrl = "http://maps.google.com/maps/api/geocode/json"
|
29
|
+
reqUrl = "#{baseUrl}?address=#{address}&sensor=false&language=ja"
|
30
|
+
response = Net::HTTP.get_response(URI.parse(reqUrl))
|
31
|
+
status = JSON.parse(response.body)
|
32
|
+
lat = status['results'][0]['geometry']['location']['lat']
|
33
|
+
lng = status['results'][0]['geometry']['location']['lng']
|
34
|
+
[lat, lng]
|
35
|
+
end
|
36
|
+
|
37
|
+
def centroid(*coordinates)
|
38
|
+
@x_sum = 0
|
39
|
+
@y_sum = 0
|
40
|
+
|
41
|
+
coordinates.each do |c|
|
42
|
+
@x_sum += c.x
|
43
|
+
@y_sum += c.y
|
44
|
+
end
|
45
|
+
|
46
|
+
[@x_sum/coordinates.length.to_f, @y_sum/coordinates.length.to_f]
|
47
|
+
end
|
48
|
+
|
49
|
+
def place_name(lat, lon)
|
50
|
+
doc = Hpricot(open("http://nishioka.sakura.ne.jp/google/ws.php?lat=#{lat}&lon=#{lon}&format=simple"))
|
51
|
+
address = doc.at(:address).inner_text
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class Coordinates
|
57
|
+
attr :x, :y
|
58
|
+
|
59
|
+
def initialize(x, y)
|
60
|
+
@x = x
|
61
|
+
@y = y
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if __FILE__ == $0
|
66
|
+
machiawase = Machiawase.new
|
67
|
+
puts machiawase.middle_of(ARGV[0], ARGV[1])
|
68
|
+
end
|
data/machiawase.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/machiawase/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["zakuni"]
|
6
|
+
gem.email = ["kunio038@gmail.com"]
|
7
|
+
gem.description = %q{provides command line usage and library to get a middle point of plural points}
|
8
|
+
gem.summary = %q{finds a middle point of plural points}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "machiawase"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Machiawase::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
gem.add_development_dependency "ZenTest"
|
20
|
+
gem.add_development_dependency "autotest-fsevent"
|
21
|
+
gem.add_development_dependency "autotest-growl"
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'machiawase'
|
4
|
+
|
5
|
+
describe Machiawase do
|
6
|
+
before do
|
7
|
+
@machiawase = Machiawase.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ":geocode" do
|
11
|
+
context '横浜' do
|
12
|
+
it 'should be 35.4437978, 139.6380256' do
|
13
|
+
@machiawase.send(:geocode, "横浜").should eq([35.4437078, 139.6380256])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ":centroid" do
|
19
|
+
context '(0, 0), (1, 1)' do
|
20
|
+
it 'should be (0.5, 0.5)' do
|
21
|
+
coordinates_a = Coordinates.new(0, 0)
|
22
|
+
coordinates_b = Coordinates.new(1, 1)
|
23
|
+
@machiawase.send(:centroid, *[coordinates_a, coordinates_b]).should eq([0.5, 0.5])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context '(0, 0), (1, 1), (2, 2)' do
|
27
|
+
it 'should be (1, 1)' do
|
28
|
+
coordinates_a = Coordinates.new(0, 0)
|
29
|
+
coordinates_b = Coordinates.new(1, 1)
|
30
|
+
coordinates_c = Coordinates.new(2, 2)
|
31
|
+
@machiawase.send(:centroid, *[coordinates_a, coordinates_b, coordinates_c]).should eq([1, 1])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context '(0, 0), (2, 0), (2, 2), (0, 2)' do
|
35
|
+
it 'should be (1, 1)' do
|
36
|
+
coordinates_a = Coordinates.new(0, 0)
|
37
|
+
coordinates_b = Coordinates.new(2, 0)
|
38
|
+
coordinates_c = Coordinates.new(2, 2)
|
39
|
+
coordinates_d = Coordinates.new(0, 2)
|
40
|
+
@machiawase.send(:centroid, *[coordinates_a, coordinates_b, coordinates_c, coordinates_d]).should eq([1, 1])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe ':place_name' do
|
46
|
+
context '35.4437078, 139.6380256' do
|
47
|
+
it 'should be 神奈川県横浜市中区真砂町一丁目1' do
|
48
|
+
@machiawase.send(:place_name, 35.4437078, 139.6380256).should eq ("神奈川県横浜市中区真砂町一丁目1")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'middle_of' do
|
54
|
+
context '横浜, 東京' do
|
55
|
+
it 'should be middle' do
|
56
|
+
@machiawase.middle_of("横浜", "東京")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: machiawase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- zakuni
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70139731153220 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70139731153220
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ZenTest
|
27
|
+
requirement: &70139731152200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70139731152200
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: autotest-fsevent
|
38
|
+
requirement: &70139731149620 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70139731149620
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: autotest-growl
|
49
|
+
requirement: &70139731148060 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70139731148060
|
58
|
+
description: provides command line usage and library to get a middle point of plural
|
59
|
+
points
|
60
|
+
email:
|
61
|
+
- kunio038@gmail.com
|
62
|
+
executables:
|
63
|
+
- machiawase
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- .autotest
|
68
|
+
- .gitignore
|
69
|
+
- Gemfile
|
70
|
+
- Gemfile.lock
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- autotest/discover.rb
|
75
|
+
- bin/machiawase
|
76
|
+
- lib/machiawase.rb
|
77
|
+
- lib/machiawase/version.rb
|
78
|
+
- machiawase.gemspec
|
79
|
+
- spec/machiawase_spec.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.17
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: finds a middle point of plural points
|
104
|
+
test_files:
|
105
|
+
- spec/machiawase_spec.rb
|
106
|
+
has_rdoc:
|