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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1eb79348e25a64d24b3d328f3315c1b10e0f71f
4
- data.tar.gz: 5fc9921379d3efe00a1ca7262711a4a6b449cb5e
3
+ metadata.gz: f11963febbbd0ddc68fcc380f3477f27f744ea42
4
+ data.tar.gz: bd1f67ae0f2136d93ea6672dc28da065fdc2d09b
5
5
  SHA512:
6
- metadata.gz: f621c515af98b98f26d7255a1e0c101dd9fd4a61168608ce121734f72122af23c1877570022f3b310190f0bf9d409b1790d916c28b45e93572a1525e0b55c77a
7
- data.tar.gz: 269517cb0a09a6c2c2385dff88b6a96fb1b8f8757f3fee8461028bedd77e0d5a149c3a40fa32168aae3d906646c1b6035880352060ece876276d63f53f9d4003
6
+ metadata.gz: d57718bf3785176a3fc31d438486ab7336fa2b4828f19a3462ab3e0ed868a562c4e3a7d09275c766b2b8df1a90046f19a0371b8d096359afc3931e8f78c969db
7
+ data.tar.gz: 8b534d820db487b40cfeac7ba46fe19cf773a6d4653d9814aac169d49a15bd118bd3d93ca518cbf18b81a064f2e266f6202be79750d8aa38589359f2bb8ec3c8
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
- # Indonesia
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/indonesia`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ # Indonesia
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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/[USERNAME]/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.
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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Indonesia
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  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.1.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-01-30 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler