ekidata 0.0.1

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ = ekidata-rails
2
+
3
+ 駅データ.jp[http://www.ekidata.jp/]のデータをRailsで簡単に扱うためのプラグイン。
4
+ RailsEngineのPluginを作る練習として実用的かなと思った。
5
+
6
+ == How to use
7
+
8
+ (1) Gemfileに追加
9
+
10
+ # Gemfile
11
+ gem 'ekidata'
12
+
13
+ (2) インストール
14
+
15
+ $ bundle install
16
+ $ bundle exec rake ekidata:install:migrations
17
+
18
+ (3) データを用意
19
+
20
+ 会員登録が必要なのと、データのメンテナンスが面倒なので、
21
+ データは 駅データ.jp[http://www.ekidata.jp/] から自前でダウンロードしてください。
22
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Ekidata'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module Ekidata
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Ekidata
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ module Ekidata
2
+ class Company < ActiveRecord::Base
3
+ attr_accessible :code,
4
+ :name,
5
+ :name_k,
6
+ :name_h,
7
+ :name_r,
8
+ :url,
9
+ :company_type,
10
+ :status,
11
+ :sort
12
+
13
+ validates :code, :presence => true, :uniqueness => true
14
+ validates :name, :presence => true
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Ekidata
2
+ class Join < ActiveRecord::Base
3
+ attr_accessible :line_code, :station_code1, :station_code2
4
+
5
+ validates :line_code, :presence => true
6
+ validates :station_code1, :presence => true
7
+ validates :station_code2, :presence => true
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Ekidata
2
+ class Line < ActiveRecord::Base
3
+ attr_accessible :code,
4
+ :company_code,
5
+ :name,
6
+ :name_k,
7
+ :name_h,
8
+ :color_code,
9
+ :color_name,
10
+ :line_type,
11
+ :google_map_zoom,
12
+ :status,
13
+ :sort
14
+
15
+ validates :code, :presence => true, :uniqueness => true
16
+ validates :company_code, :presence => true
17
+ validates :name, :presence => true
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module Ekidata
2
+ class Station < ActiveRecord::Base
3
+ attr_accessible :code, :group_code,
4
+ :name, :name_kana, :name_latin,
5
+ :line_code, :pref_code, :postal_code,
6
+ :address, :lon, :lat,
7
+ :opened_at, :closed_at,
8
+ :status, :sort,
9
+ :updated_at, :created_at
10
+
11
+ validates :code, :presence => true, :uniqueness => true
12
+ validates :group_code, :presence => true
13
+ validates :name, :presence => true
14
+ validates :line_code, :presence => true
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Ekidata</title>
5
+ <%= stylesheet_link_tag "ekidata/application", :media => "all" %>
6
+ <%= javascript_include_tag "ekidata/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Ekidata::Engine.routes.draw do
2
+ end
@@ -0,0 +1,26 @@
1
+ class CreateEkidataStations < ActiveRecord::Migration
2
+ def change
3
+ create_table :ekidata_stations do |t|
4
+ t.integer :code, :null => false
5
+ t.integer :group_code, :null => false
6
+ t.string :name, :null => false
7
+ t.string :name_kana
8
+ t.string :name_latin
9
+ t.integer :line_code, :null => false
10
+ t.integer :pref_code
11
+ t.string :postal_code
12
+ t.string :address
13
+ t.float :lon
14
+ t.float :lat
15
+ t.date :opened_at
16
+ t.date :closed_at
17
+ t.integer :status
18
+ t.integer :sort
19
+
20
+ t.timestamps
21
+ end
22
+
23
+ add_index :ekidata_stations, :code, :unique => true
24
+ add_index :ekidata_stations, :line_code
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ class CreateEkidataLines < ActiveRecord::Migration
2
+ def change
3
+ create_table :ekidata_lines do |t|
4
+ t.integer :code, :null => false
5
+ t.integer :company_code, :null => false
6
+ t.string :name, :null => false
7
+ t.string :name_k
8
+ t.string :name_h
9
+ t.string :color_code
10
+ t.string :color_name
11
+ t.integer :line_type
12
+ t.integer :google_map_zoom
13
+ t.integer :status
14
+ t.integer :sort
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ add_index :ekidata_lines, :code, :unique => true
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ class CreateEkidataCompanies < ActiveRecord::Migration
2
+ def change
3
+ create_table :ekidata_companies do |t|
4
+ t.integer :code, :null => false
5
+ t.string :name, :null => false
6
+ t.string :name_k
7
+ t.string :name_h
8
+ t.string :name_r
9
+ t.string :url
10
+ t.integer :company_type
11
+ t.integer :status
12
+ t.integer :sort
13
+
14
+ t.timestamps
15
+ end
16
+
17
+ add_index :ekidata_companies, :code, :unique => true
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ class CreateEkidataJoins < ActiveRecord::Migration
2
+ def change
3
+ create_table :ekidata_joins do |t|
4
+ t.integer :line_code, :null => false
5
+ t.integer :station_code1, :null => false
6
+ t.integer :station_code2, :null => false
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
data/lib/ekidata.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'activerecord-import'
3
+ require 'csv'
4
+ require 'ekidata/engine'
5
+ require 'ekidata/import'
@@ -0,0 +1,10 @@
1
+ module Ekidata
2
+ class Engine < ::Rails::Engine
3
+ config.generators do |g|
4
+ g.test_framework :rspec
5
+ g.integration_tool :rspec
6
+ end
7
+
8
+ isolate_namespace Ekidata
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module Ekidata
2
+ class Import
3
+ attr_accessor :model_name, :headers, :env_name
4
+
5
+ def from_csv
6
+ if ENV[@env_name].present?
7
+ model = @model_name.classify.constantize
8
+ puts model
9
+ CSV.open ENV[@env_name] do |csv|
10
+ rows = csv.map do |row|
11
+ model.new Hash[@headers.zip row.to_a]
12
+ end
13
+
14
+ puts rows.last.attributes
15
+
16
+ ActiveRecord::Base.transaction do
17
+ model.delete_all
18
+ model.import rows
19
+ end
20
+ end
21
+ else
22
+ puts "Specify #{@env_name} arguments."
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Ekidata
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,51 @@
1
+ namespace :ekidata do
2
+ namespace :import do
3
+ desc "Import all."
4
+ task :all => :environment do
5
+ Rake::Task['ekidata:import:companies'].invoke
6
+ Rake::Task['ekidata:import:lines'].invoke
7
+ Rake::Task['ekidata:import:stations'].invoke
8
+ Rake::Task['ekidata:import:joins'].invoke
9
+ end
10
+
11
+ desc "Import stations."
12
+ task :stations => :environment do
13
+ import = Ekidata::Import.new
14
+ import.model_name = 'Ekidata::Station'
15
+ import.env_name = 'STATION_CSV'
16
+ import.headers = :code, :group_code, :name, :name_kana, :name_latin, :line_code,
17
+ :pref_code, :postal_code, :address, :lon, :lat, :opened_at, :closed_at,
18
+ :status, :sort
19
+ import.from_csv
20
+ end
21
+
22
+ desc "Import lines."
23
+ task :lines => :environment do
24
+ import = Ekidata::Import.new
25
+ import.model_name = 'Ekidata::Line'
26
+ import.env_name = 'LINE_CSV'
27
+ import.headers = :code, :company_code, :name, :name_k, :name_h,
28
+ :color_code, :color_name, :line_type, :google_map_zoom, :status, :sort
29
+ import.from_csv
30
+ end
31
+
32
+ desc "Import companies."
33
+ task :companies => :environment do
34
+ import = Ekidata::Import.new
35
+ import.model_name = 'Ekidata::Company'
36
+ import.env_name = 'COMPANY_CSV'
37
+ import.headers = :code, :name, :name_k, :name_h, :name_r, :url,
38
+ :company_type, :status, :sort
39
+ import.from_csv
40
+ end
41
+
42
+ desc "Import joins."
43
+ task :joins => :environment do
44
+ import = Ekidata::Import.new
45
+ import.model_name = 'Ekidata::Join'
46
+ import.env_name = 'JOIN_CSV'
47
+ import.headers = :line_code, :station_code1, :station_code2
48
+ import.from_csv
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ekidata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hirohide Sano
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord-import
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Japanese railway station code tools.
79
+ email:
80
+ - sanojimaru@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - app/assets/javascripts/ekidata/application.js
86
+ - app/assets/stylesheets/ekidata/application.css
87
+ - app/controllers/ekidata/application_controller.rb
88
+ - app/helpers/ekidata/application_helper.rb
89
+ - app/models/ekidata/company.rb
90
+ - app/models/ekidata/join.rb
91
+ - app/models/ekidata/line.rb
92
+ - app/models/ekidata/station.rb
93
+ - app/views/layouts/ekidata/application.html.erb
94
+ - config/routes.rb
95
+ - db/migrate/20130505143741_create_ekidata_stations.rb
96
+ - db/migrate/20130505180000_create_ekidata_lines.rb
97
+ - db/migrate/20130505181327_create_ekidata_companies.rb
98
+ - db/migrate/20130506164821_create_ekidata_joins.rb
99
+ - lib/ekidata/engine.rb
100
+ - lib/ekidata/import.rb
101
+ - lib/ekidata/version.rb
102
+ - lib/ekidata.rb
103
+ - lib/tasks/ekidata_tasks.rake
104
+ - MIT-LICENSE
105
+ - Rakefile
106
+ - README.rdoc
107
+ homepage: http://github.com/sanojimaru/ekidata
108
+ licenses: []
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.23
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Japanese railway station code tools.
131
+ test_files: []