iarea 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,10 +10,10 @@ begin
10
10
  gem.homepage = "http://github.com/darashi/iarea"
11
11
  gem.authors = ["Yoji Shidara"]
12
12
 
13
- gem.add_dependency "sequel", ">= 3.10.0"
14
- gem.add_dependency "sqlite3-ruby", ">= 1.2.5"
13
+ gem.add_dependency "sequel", ">= 3.22.0"
14
+ gem.add_dependency "sqlite3-ruby", ">= 1.3.3"
15
15
 
16
- gem.add_development_dependency "rspec", ">= 1.3.0"
16
+ gem.add_development_dependency "rspec", ">= 2.5.0"
17
17
  end
18
18
  rescue LoadError
19
19
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
@@ -21,11 +21,8 @@ end
21
21
 
22
22
  Jeweler::GemcutterTasks.new
23
23
 
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:test) do |t|
26
- t.spec_files = FileList['test/**/*_test.rb']
27
- t.libs << 'test'
28
-
24
+ require 'rspec/core/rake_task.rb'
25
+ RSpec::Core::RakeTask.new(:test) do |t|
29
26
  t.verbose = true
30
27
  end
31
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/db/iareadata.sqlite3 CHANGED
Binary file
data/iarea.gemspec CHANGED
@@ -1,61 +1,59 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{iarea}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
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{2010-04-26}
12
+ s.date = %q{2011-04-04}
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 = [
16
16
  "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "MIT-LICENSE",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "db/iareadata.sqlite3",
25
- "iarea.gemspec",
26
- "lib/iarea.rb",
27
- "lib/tasks/iarea.rake",
28
- "test/iarea/iarea_test.rb",
29
- "test/test_helper.rb",
30
- "tools/import_meshes.rb"
19
+ "MIT-LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "db/iareadata.sqlite3",
24
+ "iarea.gemspec",
25
+ "lib/iarea.rb",
26
+ "lib/tasks/iarea.rake",
27
+ "spec/iarea/iarea_spec.rb",
28
+ "spec/spec_helper.rb",
29
+ "tools/import_areas.rb",
30
+ "tools/import_meshes.rb"
31
31
  ]
32
32
  s.homepage = %q{http://github.com/darashi/iarea}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
33
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.6.1}
34
+ s.rubygems_version = %q{1.5.2}
36
35
  s.summary = %q{A library for DoCoMo Open Iarea.}
37
36
  s.test_files = [
38
- "test/iarea/iarea_test.rb",
39
- "test/test_helper.rb"
37
+ "spec/iarea/iarea_spec.rb",
38
+ "spec/spec_helper.rb"
40
39
  ]
41
40
 
42
41
  if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
42
  s.specification_version = 3
45
43
 
46
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<sequel>, [">= 3.10.0"])
48
- s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
49
- s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
45
+ s.add_runtime_dependency(%q<sequel>, [">= 3.22.0"])
46
+ s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 1.3.3"])
47
+ s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
50
48
  else
51
- s.add_dependency(%q<sequel>, [">= 3.10.0"])
52
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
53
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
49
+ s.add_dependency(%q<sequel>, [">= 3.22.0"])
50
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.3"])
51
+ s.add_dependency(%q<rspec>, [">= 2.5.0"])
54
52
  end
55
53
  else
56
- s.add_dependency(%q<sequel>, [">= 3.10.0"])
57
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
58
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
54
+ s.add_dependency(%q<sequel>, [">= 3.22.0"])
55
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.3"])
56
+ s.add_dependency(%q<rspec>, [">= 2.5.0"])
59
57
  end
60
58
  end
61
59
 
data/lib/tasks/iarea.rake CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'open-uri'
3
3
  require 'tmpdir'
4
+ require 'tempfile'
4
5
 
5
6
  namespace :iarea do
6
7
  desc "generate database"
@@ -10,12 +11,10 @@ namespace :iarea do
10
11
  desc "fetch iarea metadata"
11
12
  task :def do
12
13
  uri = "http://www.nttdocomo.co.jp/service/imode/make/content/iarea/domestic/map/js/iarea_def.js"
13
- js = URI(uri).read.force_encoding('cp932').encode('UTF-8')
14
- js.sub!(%r|^var IAreaDef=new function\(\)\{|, "")
15
- data = {}
16
- js.scan %r|this\.(.+?)=(.+?);|m do |key, json|
17
- data[key] = JSON.parse(json)
18
- end
14
+ tf = Tempfile.open("iarea")
15
+ tf.write URI(uri).read
16
+ tf.close
17
+ ruby "./tools/import_areas.rb", tf.path, "db/iareadata.sqlite3"
19
18
  end
20
19
 
21
20
  desc "fetch iareadata.lzh"
@@ -26,7 +25,9 @@ namespace :iarea do
26
25
  File.open("iareadata.lzh", "w") do |f|
27
26
  f.write URI(uri).read
28
27
  end
29
- system "lha", "xf", "iareadata.lzh"
28
+ unless system("lha", "xf", "iareadata.lzh")
29
+ raise "lha failed"
30
+ end
30
31
  end
31
32
  ruby "./tools/import_meshes.rb", dir, "db/iareadata.sqlite3"
32
33
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require 'test_helper'
2
+ require 'spec_helper'
3
3
 
4
4
  describe Iarea::Utils do
5
5
  it ".lat_lng_to_meshcode" do
@@ -16,21 +16,10 @@ describe Iarea::Area do
16
16
  Iarea::Area.find_by_lat_lng(43.0568397222222,141.3478975)
17
17
  end
18
18
 
19
- it "#name" do
20
- subject.name.should == "すすきの"
21
- end
22
-
23
- it "#areacode" do
24
- subject.areacode.should == "00208"
25
- end
26
-
27
- it "#areaid" do
28
- subject.areaid.should == "002"
29
- end
30
-
31
- it "#subareaid" do
32
- subject.subareaid.should == "08"
33
- end
19
+ its(:name) { should == "すすきの" }
20
+ its(:areacode) { should == "00208" }
21
+ its(:areaid) { should == "002" }
22
+ its(:subareaid) { should == "08" }
34
23
  end
35
24
 
36
25
  context "at out of Japan" do
@@ -1,3 +1,3 @@
1
- require 'spec'
1
+ require 'rspec'
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
3
3
  require 'iarea'
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'csv'
4
+ require 'json'
5
+ require 'sequel'
6
+
7
+ if ARGV.size != 2
8
+ puts "usage #$0 [iarea_def.js] [dest_sqlite3_file]"
9
+ exit -1
10
+ end
11
+
12
+ src_path = ARGV.shift
13
+ dest_path = ARGV.shift
14
+
15
+ db = Sequel.sqlite(dest_path)
16
+
17
+ db.drop_table :zones if db.table_exists?(:zones)
18
+ db.create_table :zones do
19
+ primary_key :id
20
+ String :name
21
+ end
22
+
23
+ db.drop_table :prefectures if db.table_exists?(:prefectures)
24
+ db.create_table :prefectures do
25
+ primary_key :id
26
+ String :name
27
+ Integer :zone_id
28
+ index :zone_id
29
+ end
30
+
31
+ db.drop_table :areas if db.table_exists?(:areas)
32
+ db.create_table :areas do
33
+ String :areaid
34
+ String :subareaid
35
+ String :areacode
36
+ String :name
37
+ Integer :west
38
+ Integer :south
39
+ Integer :east
40
+ Integer :north
41
+ Integer :zone_id
42
+ Integer :prefecture_id
43
+ index :areaid
44
+ index :subareaid
45
+ index :areacode, :unique => true
46
+ index :zone_id
47
+ index :prefecture_id
48
+ end
49
+
50
+ db.transaction do
51
+ js = open(src_path, "r:cp932").read
52
+ js.sub!(%r|^var IAreaDef=new function\(\)\{|, "")
53
+ data = {}
54
+ js.scan %r|this\.(.+?)=(.+?);|m do |key, json|
55
+ data[key] = JSON.parse(json)
56
+ end
57
+ # zones
58
+ data['zones'].each_with_index do |zone, i|
59
+ $stderr.puts " importing zone %d %s" % [i, zone['name']]
60
+ db[:zones].insert(:id => i, :name => zone['name'])
61
+ end
62
+ # prefs
63
+ data['prefs'].each_with_index do |pref, i|
64
+ $stderr.puts " importing prefecture %d %s" % [i, pref['name']]
65
+ db[:prefectures].insert(:id => i, :name => pref['name'], :zone_id => pref['zone'])
66
+ end
67
+ # areas
68
+ data['areas'].each do |areacode, area|
69
+ $stderr.puts " importing area %s %s" % [areacode, area['name']]
70
+ # insert area
71
+ area = {
72
+ :areaid => areacode[0..2],
73
+ :subareaid => areacode[3..4],
74
+ :areacode => areacode,
75
+ :name => area['name'],
76
+ :west => area['msWest'],
77
+ :south => area['msSouth'],
78
+ :east => area['msEast'],
79
+ :north => area['msNorth'],
80
+ :zone_id => area['zone'],
81
+ :prefecture_id => area['pref']
82
+ }
83
+ db[:areas].insert(area)
84
+ end
85
+ end
@@ -22,19 +22,6 @@ db.create_table :meshes do
22
22
  index :areacode
23
23
  end
24
24
 
25
- db.drop_table :areas if db.table_exists?(:areas)
26
- db.create_table :areas do
27
- String :areaid
28
- String :subareaid
29
- String :areacode
30
- String :name
31
- Integer :west
32
- Integer :south
33
- Integer :east
34
- Integer :north
35
- index :areacode
36
- end
37
-
38
25
  db.transaction do
39
26
  meshes = db[:meshes]
40
27
  areas = db[:areas]
@@ -45,19 +32,9 @@ db.transaction do
45
32
  areacode = areaid + subareaid
46
33
 
47
34
  name.encode!("UTF-8")
48
- # insert area
49
- area = { :areaid => areaid,
50
- :subareaid => subareaid,
51
- :areacode => areacode,
52
- :name => name,
53
- :west => west,
54
- :south => south,
55
- :east => east,
56
- :north => north }
57
- areas.insert(area)
58
35
 
59
36
  mesh_data.pop if mesh_data.last.nil?
60
- $stderr.puts "importing area %s %s" % [areacode, name]
37
+ $stderr.puts " importing meshes %s %s" % [areacode, name]
61
38
  num_meshes = mesh_data.shift(7).map(&:to_i)
62
39
 
63
40
  expected_num_meshes = num_meshes.inject(&:+)
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iarea
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
4
+ prerelease:
5
+ version: 0.0.3
10
6
  platform: ruby
11
7
  authors:
12
8
  - Yoji Shidara
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-04-26 00:00:00 +09:00
13
+ date: 2011-04-04 00:00:00 +09:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,11 +21,7 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 3
30
- - 10
31
- - 0
32
- version: 3.10.0
24
+ version: 3.22.0
33
25
  type: :runtime
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
@@ -40,11 +32,7 @@ dependencies:
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 1
45
- - 2
46
- - 5
47
- version: 1.2.5
35
+ version: 1.3.3
48
36
  type: :runtime
49
37
  version_requirements: *id002
50
38
  - !ruby/object:Gem::Dependency
@@ -55,11 +43,7 @@ dependencies:
55
43
  requirements:
56
44
  - - ">="
57
45
  - !ruby/object:Gem::Version
58
- segments:
59
- - 1
60
- - 3
61
- - 0
62
- version: 1.3.0
46
+ version: 2.5.0
63
47
  type: :development
64
48
  version_requirements: *id003
65
49
  description: A library for DoCoMo Open Iarea.
@@ -71,7 +55,6 @@ extensions: []
71
55
  extra_rdoc_files:
72
56
  - README.rdoc
73
57
  files:
74
- - .gitignore
75
58
  - MIT-LICENSE
76
59
  - README.rdoc
77
60
  - Rakefile
@@ -80,16 +63,17 @@ files:
80
63
  - iarea.gemspec
81
64
  - lib/iarea.rb
82
65
  - lib/tasks/iarea.rake
83
- - test/iarea/iarea_test.rb
84
- - test/test_helper.rb
66
+ - spec/iarea/iarea_spec.rb
67
+ - spec/spec_helper.rb
68
+ - tools/import_areas.rb
85
69
  - tools/import_meshes.rb
86
70
  has_rdoc: true
87
71
  homepage: http://github.com/darashi/iarea
88
72
  licenses: []
89
73
 
90
74
  post_install_message:
91
- rdoc_options:
92
- - --charset=UTF-8
75
+ rdoc_options: []
76
+
93
77
  require_paths:
94
78
  - lib
95
79
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -97,24 +81,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
81
  requirements:
98
82
  - - ">="
99
83
  - !ruby/object:Gem::Version
100
- segments:
101
- - 0
102
84
  version: "0"
103
85
  required_rubygems_version: !ruby/object:Gem::Requirement
104
86
  none: false
105
87
  requirements:
106
88
  - - ">="
107
89
  - !ruby/object:Gem::Version
108
- segments:
109
- - 0
110
90
  version: "0"
111
91
  requirements: []
112
92
 
113
93
  rubyforge_project:
114
- rubygems_version: 1.3.6.1
94
+ rubygems_version: 1.5.2
115
95
  signing_key:
116
96
  specification_version: 3
117
97
  summary: A library for DoCoMo Open Iarea.
118
98
  test_files:
119
- - test/iarea/iarea_test.rb
120
- - test/test_helper.rb
99
+ - spec/iarea/iarea_spec.rb
100
+ - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- .bundle
2
- pkg