indonesia 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -5
- data/lib/indonesia.rb +12 -0
- data/lib/indonesia/district.rb +1 -1
- data/lib/indonesia/regency.rb +1 -1
- data/lib/indonesia/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f11963febbbd0ddc68fcc380f3477f27f744ea42
|
4
|
+
data.tar.gz: bd1f67ae0f2136d93ea6672dc28da065fdc2d09b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d57718bf3785176a3fc31d438486ab7336fa2b4828f19a3462ab3e0ed868a562c4e3a7d09275c766b2b8df1a90046f19a0371b8d096359afc3931e8f78c969db
|
7
|
+
data.tar.gz: 8b534d820db487b40cfeac7ba46fe19cf773a6d4653d9814aac169d49a15bd118bd3d93ca518cbf18b81a064f2e266f6202be79750d8aa38589359f2bb8ec3c8
|
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/indonesia.svg)](https://badge.fury.io/rb/indonesia)
|
2
|
+
[![Build Status](https://travis-ci.org/dimasjt/indonesia.svg?branch=master)](https://travis-ci.org/dimasjt/indonesia)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/dimasjt/indonesia/badges/gpa.svg)](https://codeclimate.com/github/dimasjt/indonesia)
|
4
|
+
|
2
5
|
|
3
|
-
|
6
|
+
# Indonesia
|
4
7
|
|
5
|
-
|
8
|
+
Get Indonesia addresses provinces, regencies and districts. Data from [edwardsamuel/Wilayah-Administratif-Indonesia](https://github.com/edwardsamuel/Wilayah-Administratif-Indonesia)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -22,7 +25,36 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
* Get all provinces
|
29
|
+
```ruby
|
30
|
+
Indonesia.provinces
|
31
|
+
```
|
32
|
+
|
33
|
+
* Get all regencies
|
34
|
+
```ruby
|
35
|
+
Indonesia.regencies
|
36
|
+
```
|
37
|
+
|
38
|
+
* Get regencies by Province ID
|
39
|
+
```ruby
|
40
|
+
Indonesia.regencies(11)
|
41
|
+
```
|
42
|
+
|
43
|
+
* Get all districts
|
44
|
+
```ruby
|
45
|
+
Indonesia.districts
|
46
|
+
```
|
47
|
+
|
48
|
+
* Get all districts by Regency ID
|
49
|
+
```ruby
|
50
|
+
Indonesia.districts(1101)
|
51
|
+
```
|
52
|
+
|
53
|
+
### Rails select options element
|
54
|
+
|
55
|
+
```erb
|
56
|
+
<%= f.select :province_id, options_for_select(Indonesia.provinces.map { |province| [province[:name], province[:id]] }) %>
|
57
|
+
```
|
26
58
|
|
27
59
|
## Development
|
28
60
|
|
@@ -32,7 +64,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
64
|
|
33
65
|
## Contributing
|
34
66
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dimasjt/indonesia. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
68
|
|
37
69
|
|
38
70
|
## License
|
data/lib/indonesia.rb
CHANGED
@@ -4,4 +4,16 @@ require 'indonesia/regency'
|
|
4
4
|
require 'indonesia/district'
|
5
5
|
|
6
6
|
module Indonesia
|
7
|
+
def self.options_for_select(type = :province, parent_id = nil)
|
8
|
+
case type
|
9
|
+
when :province
|
10
|
+
provinces.map { |province| [province[:name], province[:id]] }
|
11
|
+
when :regency
|
12
|
+
regencies(parent_id).map { |regency| [regency[:name], regency[:id]] }
|
13
|
+
when :district
|
14
|
+
districts(parent_id).map { |district| [district[:name], district[:id]] }
|
15
|
+
else
|
16
|
+
[]
|
17
|
+
end
|
18
|
+
end
|
7
19
|
end
|
data/lib/indonesia/district.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Indonesia
|
2
2
|
def self.districts(regency_id = nil)
|
3
3
|
return self.all_districts if regency_id.nil?
|
4
|
-
self.all_districts.select { |district| district[:regency_id] == regency_id }
|
4
|
+
self.all_districts.select { |district| district[:regency_id] == regency_id.to_i }
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.all_districts
|
data/lib/indonesia/regency.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Indonesia
|
2
2
|
def self.regencies(province_id = nil)
|
3
3
|
return self.all_regencies if province_id.nil?
|
4
|
-
self.all_regencies.select { |regency| regency[:province_id] == province_id }
|
4
|
+
self.all_regencies.select { |regency| regency[:province_id] == province_id.to_i }
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.all_regencies
|
data/lib/indonesia/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|