indonesia 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f11963febbbd0ddc68fcc380f3477f27f744ea42
4
- data.tar.gz: bd1f67ae0f2136d93ea6672dc28da065fdc2d09b
3
+ metadata.gz: dd0de06b8a89de70689ed3c119e404d2f4a6eabd
4
+ data.tar.gz: 7d288ae0e5da082f9b57899c897f436a847806b6
5
5
  SHA512:
6
- metadata.gz: d57718bf3785176a3fc31d438486ab7336fa2b4828f19a3462ab3e0ed868a562c4e3a7d09275c766b2b8df1a90046f19a0371b8d096359afc3931e8f78c969db
7
- data.tar.gz: 8b534d820db487b40cfeac7ba46fe19cf773a6d4653d9814aac169d49a15bd118bd3d93ca518cbf18b81a064f2e266f6202be79750d8aa38589359f2bb8ec3c8
6
+ metadata.gz: 0345b0e20b75522a736d2deb553943efee1ba27346747cd42767d4b50fe907ac43bbafc9c5be5592496c326779e216a34b3a36dcf7dae93c7dc8a42388b5f2f5
7
+ data.tar.gz: a2c3f75f6fa8efa4336b0fb7a0686a572dcc8f0cad79a72abe50c110b7db3f039520cadb8e614cbe6d84cc72e40adf60e468e46c7919f6ffb16eb383126244e3
data/CODE_OF_CONDUCT.md CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at dimas.taniawan@bocistudio.com. All
58
+ reported by contacting the project team at dimazniawan@gmail.com. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Get Indonesia addresses provinces, regencies and districts. Data from [edwardsam
12
12
  Add this line to your application's Gemfile:
13
13
 
14
14
  ```ruby
15
- gem 'indonesia'
15
+ gem 'indonesia', '~> 0.2.0'
16
16
  ```
17
17
 
18
18
  And then execute:
@@ -28,11 +28,17 @@ Or install it yourself as:
28
28
  * Get all provinces
29
29
  ```ruby
30
30
  Indonesia.provinces
31
+
32
+ # result
33
+ => [{:id=>11, :name=>"ACEH"}, {:id=>12, :name=>"SUMATERA UTARA"}, ...]
31
34
  ```
32
35
 
33
36
  * Get all regencies
34
37
  ```ruby
35
38
  Indonesia.regencies
39
+
40
+ # result
41
+ => [{:id=>1101, :province_id=>11, :name=>"KABUPATEN SIMEULUE"}, ...]
36
42
  ```
37
43
 
38
44
  * Get regencies by Province ID
@@ -43,6 +49,9 @@ Indonesia.regencies(11)
43
49
  * Get all districts
44
50
  ```ruby
45
51
  Indonesia.districts
52
+
53
+ # result
54
+ => [{:id=>1101010, :regency_id=>1101, :name=>"TEUPAH SELATAN"}, ...]
46
55
  ```
47
56
 
48
57
  * Get all districts by Regency ID
@@ -50,10 +59,48 @@ Indonesia.districts
50
59
  Indonesia.districts(1101)
51
60
  ```
52
61
 
53
- ### Rails select options element
62
+ ### Rails select options
63
+
64
+ #### #options_for_select (:province, :regency, :district)
65
+ ```ruby
66
+ # provinces
67
+ Indonesia.options_for_select(:province)
68
+
69
+ # result
70
+ => [["ACEH", 11], ["SUMATERA UTARA", 12], ["SUMATERA BARAT", 13], ...]
71
+
72
+ # regencies
73
+ Indonesia.options_for_select(:regency)
74
+ # or
75
+ Indonesia.options_for_select(:regency, 11) # 11 is province_id
76
+
77
+ # result
78
+ => [["KABUPATEN SIMEULUE", 1101], ["KABUPATEN ACEH SINGKIL", 1102], ...]
79
+
80
+ # districts
81
+ Indonesia.options_for_select(:district, 1101) # 1101 is regency_id
82
+
83
+ # result
84
+ => [["TEUPAH SELATAN", 1101010], ["SIMEULUE TIMUR", 1101020], ...]
85
+ ```
86
+ #### Generate for select options rails
87
+ * Province
88
+ ```erb
89
+ <%= f.select :province_id, Indonesia.options_for_select(:province) %>
90
+ ```
91
+
92
+ * Regency
93
+ ```erb
94
+ <%= f.select :regency_id, Indonesia.options_for_select(:regency) %>
95
+ or
96
+ <%= f.select :regency_id, Indonesia.options_for_select(:regency, 11) %>
97
+ ```
54
98
 
99
+ * District
55
100
  ```erb
56
- <%= f.select :province_id, options_for_select(Indonesia.provinces.map { |province| [province[:name], province[:id]] }) %>
101
+ <%= f.select :district_id, Indonesia.options_for_select(:district) %>
102
+ or
103
+ <%= f.select :district_id, Indonesia.options_for_select(:district, 1101) %>
57
104
  ```
58
105
 
59
106
  ## Development
@@ -1,3 +1,3 @@
1
1
  module Indonesia
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/indonesia.rb CHANGED
@@ -16,4 +16,17 @@ module Indonesia
16
16
  []
17
17
  end
18
18
  end
19
+
20
+ def self.find(type, query)
21
+ address = %w(province regency district)
22
+ types = address + address.map(&:to_sym)
23
+
24
+ if types.include? type
25
+ # manual using pluralize
26
+ type = type.to_s == 'regency' ? 'regencies' : "#{type}s"
27
+ self.send(type).find { |t| t[:name].downcase == query.downcase }
28
+ else
29
+ nil
30
+ end
31
+ end
19
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indonesia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimas J. Taniawan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.5.1
97
+ rubygems_version: 2.5.2
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Indonesia addresses