propinsi 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.
@@ -0,0 +1,106 @@
1
+ # All data
2
+ # Taken from http://mfdonline.bps.go.id Feb 2016
3
+ ---
4
+ provinces:
5
+ - name: Aceh
6
+ id: 1
7
+
8
+ - name: Sumatera Utara
9
+ id: 2
10
+
11
+ - name: Sumatera Barat
12
+ id: 3
13
+
14
+ - name: Riau
15
+ id: 4
16
+
17
+ - name: Jambi
18
+ id: 5
19
+
20
+ - name: Sumatera Selatan
21
+ id: 6
22
+
23
+ - name: Bengkulu
24
+ id: 7
25
+
26
+ - name: Lampung
27
+ id: 8
28
+
29
+ - name: Kepulauan Bangka Belitung
30
+ id: 9
31
+
32
+ - name: Kepulauan Riau
33
+ id: 10
34
+
35
+ - name: Dki Jakarta
36
+ id: 11
37
+
38
+ - name: Jawa Barat
39
+ id: 12
40
+
41
+ - name: Jawa Tengah
42
+ id: 13
43
+
44
+ - name: Di Yogyakarta
45
+ id: 14
46
+
47
+ - name: Jawa Timur
48
+ id: 15
49
+
50
+ - name: Banten
51
+ id: 16
52
+
53
+ - name: Bali
54
+ id: 17
55
+
56
+ - name: Nusa Tenggara Barat
57
+ id: 18
58
+
59
+ - name: Nusa Tenggara Timur
60
+ id: 19
61
+
62
+ - name: Kalimantan Barat
63
+ id: 20
64
+
65
+ - name: Kalimantan Tengah
66
+ id: 21
67
+
68
+ - name: Kalimantan Selatan
69
+ id: 22
70
+
71
+ - name: Kalimantan Timur
72
+ id: 23
73
+
74
+ - name: Kalimantan Utara
75
+ id: 24
76
+
77
+ - name: Sulawesi Utara
78
+ id: 25
79
+
80
+ - name: Sulawesi Tengah
81
+ id: 26
82
+
83
+ - name: Sulawesi Selatan
84
+ id: 27
85
+
86
+ - name: Sulawesi Tenggara
87
+ id: 28
88
+
89
+ - name: Gorontalo
90
+ id: 29
91
+
92
+ - name: Sulawesi Barat
93
+ id: 30
94
+
95
+ - name: Maluku
96
+ id: 31
97
+
98
+ - name: Maluku Utara
99
+ id: 32
100
+
101
+ - name: Papua Barat
102
+ id: 33
103
+
104
+ - name: Papua
105
+ id: 34
106
+
@@ -0,0 +1,49 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+ require 'yaml'
4
+
5
+ module Propinsi
6
+ class InstallGenerator < Rails::Generators::Base
7
+ # source_root File.expand_path("../../templates", __FILE__)
8
+ desc "This generator will create model and db seed"
9
+
10
+ def create_initializer_file
11
+ create_file "lib/tasks/propinsi.rake", "# task province \nnamespace :propinsi do \n desc \"Dump all data\" \n task :import => :environment do \n end \nend\n"
12
+ end
13
+
14
+
15
+ def create_migration
16
+ # Generate Propinsi
17
+ generate 'model', "province name:string --no-timestamps"
18
+ # generate Kota
19
+ generate 'model', "city province_id:string name:string --no-timestamps"
20
+ end
21
+
22
+ def create_db_seed
23
+ filepath = File.join(File.dirname(__FILE__), '../../data/all.yml')
24
+ @data = YAML.load_file(filepath)
25
+ text = "\n\n"
26
+ city_id=0;
27
+ @data["provinces"].map.each do |row|
28
+ # puts row["name"];
29
+ # puts "\n break"
30
+ text << "Province.find_or_create_by(id: #{row["id"]}, name: '#{row["name"]}') \n"
31
+ row["cities"].map.with_index.each do |row2,idx|
32
+ city_id=city_id+1;
33
+ # puts row2
34
+ text << "City.find_or_create_by(id: #{city_id}, name: '#{row2["name"]}', province_id: '#{row2["province_id"]}') \n"
35
+ end
36
+ end
37
+
38
+ # puts text;
39
+ inject_into_file 'lib/tasks/propinsi.rake', text, after: "task :import => :environment do"
40
+ #inject into province model
41
+ province_text="\nhas_many :cities\nvalidates_presence_of :name"
42
+ inject_into_file 'app/models/province.rb', province_text, after: "class Province < ActiveRecord::Base"
43
+ #inject into city model
44
+ city_text="\nbelongs_to :province\nvalidates_presence_of :name"
45
+ inject_into_file 'app/models/city.rb', city_text, after: "class City < ActiveRecord::Base"
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+ require 'rails/generators/named_base'
4
+
5
+ module Propinsi
6
+ class KotaGenerator < Rails::Generators::NamedBase
7
+
8
+ desc "This generator will create model and db seed"
9
+
10
+ def create_migration
11
+ generate 'model', "#{class_name} name:string --no-timestamps"
12
+ end
13
+
14
+ def create_db_seed
15
+ text = "\n\n"
16
+ text << Prefectures.map.with_index(1) do |name, idx|
17
+ "#{class_name}.find_or_create_by(id: #{idx}, name: '#{name}')"
18
+ end.join("\n")
19
+
20
+ inject_into_file 'db/seeds.rb', text.force_encoding('ascii-8bit'), after: /.\Z/
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+ require 'rails/generators/named_base'
4
+
5
+ module Propinsi
6
+ class PropinsiGenerator < Rails::Generators::NamedBase
7
+ # source_root File.expand_path("../../templates", __FILE__)
8
+ desc "This generator will create model and db seed"
9
+
10
+ def create_migration
11
+ generate 'model', "#{class_name} name:string --no-timestamps"
12
+ end
13
+
14
+ def create_db_seed
15
+ text = "\n\n"
16
+ text << Prefectures.map.with_index(1) do |name, idx|
17
+ "#{class_name}.find_or_create_by(id: #{idx}, name: '#{name}')"
18
+ end.join("\n")
19
+
20
+ inject_into_file 'db/seeds.rb', text.force_encoding('ascii-8bit'), after: /.\Z/
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Propinsi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/propinsi.rb ADDED
@@ -0,0 +1,47 @@
1
+ require "propinsi/version"
2
+ require 'yaml'
3
+ module Propinsi
4
+ # Your code goes here...
5
+ def Propinsi.all
6
+ filepath = File.join(File.dirname(__FILE__), 'data/all.yml')
7
+ all=YAML.load_file(filepath);
8
+ return all["provinces"]
9
+ end
10
+
11
+ def Propinsi.propinsi
12
+ filepath = File.join(File.dirname(__FILE__), 'data/provinces.yml')
13
+ prop=YAML.load_file(filepath);
14
+ return prop["provinces"]
15
+ end
16
+
17
+ def Propinsi.kota
18
+ filepath = File.join(File.dirname(__FILE__), 'data/cities.yml')
19
+ kota=YAML.load_file(filepath);
20
+ return kota["cities"];
21
+ end
22
+
23
+ def Propinsi.findkota(input)
24
+ kota=self.kota;
25
+ index=kota.each_with_index do |row,idx|
26
+ break idx if(input.to_s == row["id"].to_s || input.to_s == row["name"].to_s)
27
+ end
28
+ if index.kind_of?(Array)
29
+ return false;
30
+ else
31
+ return kota[index]
32
+ end
33
+
34
+ end
35
+
36
+ def Propinsi.findpropinsi(input)
37
+ prop=self.all
38
+ index=prop.each_with_index do |row,idx|
39
+ break idx if(input.to_s == row["id"].to_s || input.to_s == row["name"].to_s)
40
+ end
41
+ if index.kind_of?(Array)
42
+ return false;
43
+ else
44
+ return prop[index]
45
+ end
46
+ end
47
+ end
data/propinsi.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'propinsi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "propinsi"
8
+ spec.version = Propinsi::VERSION
9
+ spec.authors = ["Perdana Adhitama"]
10
+ spec.email = ["perdana_adhitama@yahoo.com"]
11
+
12
+ spec.summary = "Propinsi master table"
13
+ spec.description = "Propinsi master table"
14
+ spec.homepage = "http://github.com/kovloq/propinsi"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: propinsi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Perdana Adhitama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Propinsi master table
42
+ email:
43
+ - perdana_adhitama@yahoo.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".DS_Store"
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/data/all.yml
59
+ - lib/data/cities.yml
60
+ - lib/data/provinces.yml
61
+ - lib/generators/propinsi/install_generator.rb
62
+ - lib/generators/propinsi/kota_generator.rb
63
+ - lib/generators/propinsi/propinsi_generator.rb
64
+ - lib/propinsi.rb
65
+ - lib/propinsi/version.rb
66
+ - propinsi.gemspec
67
+ homepage: http://github.com/kovloq/propinsi
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.6.4
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Propinsi master table
91
+ test_files: []