iarea 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  A library for DoCoMo Open Iarea.
4
4
 
5
+ = Instration
6
+
7
+ % gem install iarea
8
+
9
+ or add
10
+
11
+ gem 'iarea'
12
+
13
+ on your Gemfile.
14
+
5
15
  = Example of use
6
16
 
7
17
  require 'iarea'
@@ -11,9 +21,14 @@ A library for DoCoMo Open Iarea.
11
21
  area.areacode # => "00208"
12
22
  area.zone.name # => "北海道"
13
23
  area.prefecture.name # => "北海道"
24
+ area.neighbors.map(&:name) #=> ["大通公園周辺", "大通東", "山鼻/藻岩周辺", "中島公園周辺"]
25
+
26
+ = Resources
27
+
28
+ * {Documentation}[http://rdoc.info/github/darashi/iarea/master/frames]
14
29
 
15
30
  = References
16
31
 
17
32
  http://www.nttdocomo.co.jp/service/imode/make/content/iarea/domestic/index.html
18
33
 
19
- db/iareadata.sqlite3 contains the data extracted from http://www.nttdocomo.co.jp/binary/archive/service/imode/make/content/iarea/domestic/iareadata.lzh .
34
+ db/iareadata.sqlite3 contains the data extracted from http://www.nttdocomo.co.jp/binary/archive/service/imode/make/content/iarea/domestic/iareadata.lzh and http://www.nttdocomo.co.jp/service/imode/make/content/iarea/domestic/map/js/iarea_def.js.
data/Rakefile CHANGED
@@ -27,4 +27,14 @@ RSpec::Core::RakeTask.new(:test) do |t|
27
27
  t.verbose = true
28
28
  end
29
29
 
30
+ require 'rake/rdoctask'
31
+ Rake::RDocTask.new do |rdoc|
32
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
33
+
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = "iarea #{version}"
36
+ rdoc.rdoc_files.include('README*')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
39
+
30
40
  task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/iarea.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{iarea}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoji Shidara"]
12
- s.date = %q{2011-04-07}
12
+ s.date = %q{2011-04-09}
13
13
  s.description = %q{A library for DoCoMo Open Iarea.}
14
14
  s.email = %q{dara@shidara.net}
15
15
  s.extra_rdoc_files = [
@@ -23,6 +23,10 @@ Gem::Specification.new do |s|
23
23
  "db/iareadata.sqlite3",
24
24
  "iarea.gemspec",
25
25
  "lib/iarea.rb",
26
+ "lib/iarea/area.rb",
27
+ "lib/iarea/prefecture.rb",
28
+ "lib/iarea/utils.rb",
29
+ "lib/iarea/zone.rb",
26
30
  "lib/tasks/iarea.rake",
27
31
  "spec/iarea/area_spec.rb",
28
32
  "spec/iarea/prefecture_spec.rb",
data/lib/iarea/area.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Iarea
2
+ # Area
3
+ class Area < OpenStruct
4
+ @@areas = {}
5
+
6
+ # Prefecture of the area
7
+ def prefecture
8
+ Prefecture.find(self.prefecture_id)
9
+ end
10
+
11
+ # Zone of the area
12
+ def zone
13
+ Zone.find(self.zone_id)
14
+ end
15
+
16
+ # Neighbor areas of the area
17
+ def neighbors
18
+ DB[:neighbors].where(:areacode => areacode).select(:neighbor_areacode).map do |neighbor|
19
+ Area.find neighbor[:neighbor_areacode]
20
+ end
21
+ end
22
+
23
+ class << self
24
+ # Find area by <tt>areacode</tt>
25
+ def find(areacode)
26
+ @@areas[areacode] ||= new DB[:areas].where(:areacode => areacode).first
27
+ end
28
+
29
+ # Find area by latitude and longitude in degrees
30
+ def find_by_lat_lng(lat, lng)
31
+ meshcodes = Utils.expand_meshcode(Utils.lat_lng_to_meshcode(lat, lng))
32
+ area = DB[:meshes].where(:meshcode => meshcodes).select(:areacode).first
33
+ return nil if area.nil?
34
+ find(area[:areacode])
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ module Iarea
2
+ # Prefecture
3
+ class Prefecture < OpenStruct
4
+ @@prefectures = []
5
+
6
+ # Zone of the prefecture
7
+ def zone
8
+ Zone.find(self.zone_id)
9
+ end
10
+
11
+ # Areas in the prefecture
12
+ def areas
13
+ DB[:areas].where(:prefecture_id => self.id).select(:areacode).order(:areacode).map do |area|
14
+ Area.find(area[:areacode])
15
+ end
16
+ end
17
+
18
+ class << self
19
+ # Find a prefecture by <tt>id</tt>
20
+ def find(id)
21
+ @@prefectures[id] ||= new DB[:prefectures].where(:id => id).first
22
+ end
23
+
24
+ # All prefectures
25
+ def all
26
+ DB[:prefectures].select(:id).order(:id).all.map{ |pr| find(pr[:id]) }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ module Iarea
2
+ # Utility module
3
+ module Utils
4
+ LAT_WIDTH = [nil,2400000,300000,150000, 75000,37500,18750, 9375 ]
5
+ LON_WIDTH = [nil,3600000,450000,225000,112500,56250,28125,14062.5]
6
+ class << self
7
+ # Return 7th meshcode of given coordinates
8
+ def lat_lng_to_meshcode(lat_deg, lng_deg)
9
+ lat = (lat_deg * 3600000).to_i
10
+ lng = (lng_deg * 3600000).to_i
11
+ meshcode = ''
12
+ la = lat
13
+ lo = lng - 100*60*60*1000
14
+ for i in 1..7
15
+ a = (la / LAT_WIDTH[i]).to_i
16
+ b = (lo / LON_WIDTH[i]).to_i
17
+ la -= a * LAT_WIDTH[i]
18
+ lo -= b * LON_WIDTH[i]
19
+ case i
20
+ when 1
21
+ meshcode = sprintf("%02d%02d",a,b)
22
+ when 2
23
+ meshcode << sprintf("%d%d",a,b)
24
+ else
25
+ meshcode << sprintf("%d",a*2+b)
26
+ end
27
+ end
28
+ return meshcode
29
+ end
30
+
31
+ # Return array of 1th..7th meshcodes for the given 7th meshcode
32
+ def expand_meshcode(meshcode)
33
+ (6..12).map do |n|
34
+ meshcode[0, n]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
data/lib/iarea/zone.rb ADDED
@@ -0,0 +1,27 @@
1
+ module Iarea
2
+ class Zone < OpenStruct
3
+ @@zones = []
4
+
5
+ def prefectures
6
+ DB[:prefectures].where(:zone_id => self.id).select(:id).order(:id).map do |prefecture|
7
+ Prefecture.find(prefecture[:id])
8
+ end
9
+ end
10
+
11
+ def areas
12
+ DB[:areas].where(:zone_id => self.id).select(:areacode).order(:areacode).map do |area|
13
+ Area.find(area[:areacode])
14
+ end
15
+ end
16
+
17
+ class << self
18
+ def find(id)
19
+ @@zones[id] ||= new DB[:zones].where(:id => id).first
20
+ end
21
+
22
+ def all
23
+ DB[:zones].select(:id).order(:id).all.map{ |z| find(z[:id]) }
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/iarea.rb CHANGED
@@ -1,120 +1,10 @@
1
1
  require 'sequel'
2
2
  require 'ostruct'
3
3
 
4
- module Iarea
5
- DB = Sequel.sqlite(File.expand_path("../../db/iareadata.sqlite3", __FILE__))
6
-
7
- class Area < OpenStruct
8
- @@areas = {}
9
- def prefecture
10
- Prefecture.find(self.prefecture_id)
11
- end
12
-
13
- def zone
14
- Zone.find(self.zone_id)
15
- end
16
-
17
- def neighbors
18
- DB[:neighbors].where(:areacode => areacode).select(:neighbor_areacode).map do |neighbor|
19
- Area.find neighbor[:neighbor_areacode]
20
- end
21
- end
22
-
23
- class << self
24
- def find(areacode)
25
- @@areas[areacode] ||= new DB[:areas].where(:areacode => areacode).first
26
- end
27
-
28
- def find_by_lat_lng(lat, lng)
29
- meshcodes = Utils.expand_meshcode(Utils.lat_lng_to_meshcode(lat, lng))
30
- area = DB[:meshes].where(:meshcode => meshcodes).select(:areacode).first
31
- return nil if area.nil?
32
- find(area[:areacode])
33
- end
34
- end
35
- end
36
-
37
- class Zone < OpenStruct
38
- @@zones = []
39
-
40
- def prefectures
41
- DB[:prefectures].where(:zone_id => self.id).select(:id).order(:id).map do |prefecture|
42
- Prefecture.find(prefecture[:id])
43
- end
44
- end
45
-
46
- def areas
47
- DB[:areas].where(:zone_id => self.id).select(:areacode).order(:areacode).map do |area|
48
- Area.find(area[:areacode])
49
- end
50
- end
51
-
52
- class << self
53
- def find(id)
54
- @@zones[id] ||= new DB[:zones].where(:id => id).first
55
- end
56
-
57
- def all
58
- DB[:zones].select(:id).order(:id).all.map{ |z| find(z[:id]) }
59
- end
60
- end
61
- end
62
-
63
- class Prefecture < OpenStruct
64
- @@prefectures = []
65
- def zone
66
- Zone.find(self.zone_id)
67
- end
68
-
69
- def areas
70
- DB[:areas].where(:prefecture_id => self.id).select(:areacode).order(:areacode).map do |area|
71
- Area.find(area[:areacode])
72
- end
73
- end
74
-
75
- class << self
76
- def find(id)
77
- @@prefectures[id] ||= new DB[:prefectures].where(:id => id).first
78
- end
79
-
80
- def all
81
- DB[:prefectures].select(:id).order(:id).all.map{ |pr| find(pr[:id]) }
82
- end
83
- end
84
- end
85
-
86
- module Utils
87
- LAT_WIDTH = [nil,2400000,300000,150000, 75000,37500,18750, 9375 ]
88
- LON_WIDTH = [nil,3600000,450000,225000,112500,56250,28125,14062.5]
89
- class << self
90
- def lat_lng_to_meshcode(lat_deg, lng_deg)
91
- lat = (lat_deg * 3600000).to_i
92
- lng = (lng_deg * 3600000).to_i
93
- meshcode = ''
94
- la = lat
95
- lo = lng - 100*60*60*1000
96
- for i in 1..7
97
- a = (la / LAT_WIDTH[i]).to_i
98
- b = (lo / LON_WIDTH[i]).to_i
99
- la -= a * LAT_WIDTH[i]
100
- lo -= b * LON_WIDTH[i]
101
- case i
102
- when 1
103
- meshcode = sprintf("%02d%02d",a,b)
104
- when 2
105
- meshcode << sprintf("%d%d",a,b)
106
- else
107
- meshcode << sprintf("%d",a*2+b)
108
- end
109
- end
110
- return meshcode
111
- end
112
-
113
- def expand_meshcode(meshcode)
114
- (6..12).map do |n|
115
- meshcode[0, n]
116
- end
117
- end
118
- end
119
- end
4
+ module Iarea # :nodoc:
5
+ DB = Sequel.sqlite(File.expand_path("../../db/iareadata.sqlite3", __FILE__)) # :nodoc:
6
+ autoload :Area, File.expand_path('../iarea/area', __FILE__)
7
+ autoload :Zone, File.expand_path('../iarea/zone', __FILE__)
8
+ autoload :Prefecture, File.expand_path('../iarea/prefecture', __FILE__)
9
+ autoload :Utils, File.expand_path('../iarea/utils', __FILE__)
120
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iarea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-07 00:00:00.000000000 +09:00
12
+ date: 2011-04-09 00:00:00.000000000 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sequel
17
- requirement: &2160917720 !ruby/object:Gem::Requirement
17
+ requirement: &2156749600 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.22.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2160917720
25
+ version_requirements: *2156749600
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3-ruby
28
- requirement: &2160914320 !ruby/object:Gem::Requirement
28
+ requirement: &2156748680 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.3.3
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2160914320
36
+ version_requirements: *2156748680
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2160913380 !ruby/object:Gem::Requirement
39
+ requirement: &2156747540 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 2.5.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2160913380
47
+ version_requirements: *2156747540
48
48
  description: A library for DoCoMo Open Iarea.
49
49
  email: dara@shidara.net
50
50
  executables: []
@@ -59,6 +59,10 @@ files:
59
59
  - db/iareadata.sqlite3
60
60
  - iarea.gemspec
61
61
  - lib/iarea.rb
62
+ - lib/iarea/area.rb
63
+ - lib/iarea/prefecture.rb
64
+ - lib/iarea/utils.rb
65
+ - lib/iarea/zone.rb
62
66
  - lib/tasks/iarea.rake
63
67
  - spec/iarea/area_spec.rb
64
68
  - spec/iarea/prefecture_spec.rb