kisyo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,30 @@
1
1
  require 'csv'
2
+ require 'geocoder'
2
3
 
3
4
  module Kisyo
4
5
  class Location
5
6
  attr_reader :prefecture_id, :block_id
6
7
 
8
+ def self.distance(lat1, lng1, lat2, lng2)
9
+ Geocoder::Calculations.distance_between([lat1, lng1], [lat2, lng2])
10
+ end
11
+
7
12
  def self.dms_to_degrees(d, m, s = 0)
8
13
  d + m / 60.0 + s / 3600.0
9
14
  end
10
15
 
11
16
  def self.nearest(lat, lng)
12
- CSV.open(File.dirname(__FILE__) + '/../blocks.csv') do |csv|
13
- distances =
14
- csv.map do |row|
15
- la = dms_to_degrees(row[5].to_f, row[6].to_f)
16
- ln = dms_to_degrees(row[7].to_f, row[8].to_f)
17
+ distances =
18
+ BLOCKS.map do |block|
19
+ la = dms_to_degrees(block[3].to_f, block[4].to_f)
20
+ ln = dms_to_degrees(block[5].to_f, block[6].to_f)
17
21
 
18
- [Math.sqrt((lat - la)**2 + (lng - ln)**2), row]
19
- end
22
+ [distance(lat, lng, la, ln), block]
23
+ end
20
24
 
21
- distance = distances.min_by { |(dist, _)| dist }
22
- row = distance[1]
25
+ block = distances.min_by { |(dist, _)| dist }[1]
23
26
 
24
- new(row[3], row[4])
25
- end
27
+ new(block[1], block[2])
26
28
  end
27
29
 
28
30
  def initialize(prefecture_id, block_id)
data/lib/kisyo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kisyo
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/kisyo.rb CHANGED
@@ -1,9 +1,10 @@
1
- require "kisyo/error"
2
- require "kisyo/location"
3
- require "kisyo/cache"
4
- require "kisyo/daily"
5
- require "kisyo/elements/day"
6
- require "kisyo/version"
1
+ require 'kisyo/error'
2
+ require 'kisyo/blocks'
3
+ require 'kisyo/location'
4
+ require 'kisyo/cache'
5
+ require 'kisyo/daily'
6
+ require 'kisyo/elements/day'
7
+ require 'kisyo/version'
7
8
 
8
9
  module Kisyo
9
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kisyo
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
  - youpy
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: geocoder
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: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +94,8 @@ files:
80
94
  - README.md
81
95
  - Rakefile
82
96
  - kisyo.gemspec
83
- - lib/blocks.csv
84
97
  - lib/kisyo.rb
98
+ - lib/kisyo/blocks.rb
85
99
  - lib/kisyo/cache.rb
86
100
  - lib/kisyo/daily.rb
87
101
  - lib/kisyo/elements/day.rb