municipitaly 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be1c36e7a1dad85d624b795a4d2c38a4a75d4289a42f1f3ee761641f62a06c7f
4
- data.tar.gz: 321ca54451a996bbe0164f267be770d5de0f60882d9a4ca79a659016e18fcff6
3
+ metadata.gz: ac3d4c00b1b7bdb813715e766feda06ea45c699871cfa5275a1be11b14d8040a
4
+ data.tar.gz: 85371d88cda566a0a57eb2e425cd024378a94741ab5f90ab57ea8bb37f439aac
5
5
  SHA512:
6
- metadata.gz: 5451db5babc9842f826ef39249386f93bbe93e90744291a395eb25923b64edc6b7b03c0a0daac76e0543699a1572d5c71273e0ddf1b127b9dd6d44ff6ee132c3
7
- data.tar.gz: 818d5b215a467dc93ddd3a70fb8c2095ea720c338ca1e0d1131de4d3d6217ee9ee21008ebfaece13f4642617240791109fc42c8942cd50c151e1e54dbdf4054f
6
+ metadata.gz: c47bcf525cc0a6d73fb8023f182330797ab38be769619bdcc919d513115f8f7d1c37ec369f86ee12e024586cfbd752e5e96207b8e96a6c224f6945eb1f4184dd
7
+ data.tar.gz: 61ea4f864d72f403033089f5ad8b32601e15fb0af321246e80720488f4e5e8c76416cea2861760abed5343f13216b7e0ad1f766a7bc636fe3b1a5180cf5a3126
@@ -4,6 +4,9 @@ Metrics/BlockLength:
4
4
  - 'municipitaly.gemspec'
5
5
  - 'lib/**/*.rb'
6
6
  - 'spec/**/*.rb'
7
+ Metrics/ClassLength:
8
+ Exclude:
9
+ - 'lib/municipitaly/search.rb'
7
10
 
8
11
  Metrics/ParameterLists:
9
12
  Max: 10
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- municipitaly (0.0.1)
4
+ municipitaly (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -55,6 +55,9 @@ Returned data are stored in 4 different types of entity models:
55
55
  Retrieve all zones (return an array of `Municipitaly::Zone` objects):
56
56
 
57
57
  ```ruby
58
+ # inside an irb or rails console:
59
+ require 'municipitaly'
60
+
58
61
  zones = Municipitaly::Zone.all
59
62
  # => [#<Municipitaly::Zone:0x0000...]
60
63
  ```
@@ -69,6 +72,7 @@ retrive data zone:
69
72
  ```ruby
70
73
  zone.name
71
74
  # => "Centro"
75
+
72
76
  zone.code
73
77
  # => "3"
74
78
  ```
@@ -179,7 +183,7 @@ If you want to contribute keep these guidelines in mind:
179
183
  Steps to submit your code:
180
184
 
181
185
  1. Fork the repo.
182
- 2. Oper your feature/namespaced branch
186
+ 2. Open your feature/namespaced branch
183
187
  3. Commit your code following Github guidelines.
184
188
  4. Make a PR with an exhaustive description.
185
189
 
@@ -53,7 +53,7 @@ module Municipitaly
53
53
 
54
54
  def find_csv(file)
55
55
  File.expand_path(File.join(File.dirname(__FILE__),
56
- "../../vendor/data/#{file}"))
56
+ "../../vendor/data/#{file}"))
57
57
  end
58
58
  end
59
59
  end
@@ -26,15 +26,16 @@ module Municipitaly
26
26
  municipalities_from_zone_code].freeze # :nodoc:
27
27
 
28
28
  CLASS_METHODS.each do |method|
29
- define_singleton_method method do |message|
30
- Search.new(message).send(method)
29
+ define_singleton_method method do |message, opts = {}|
30
+ Search.new(message, opts).send(method)
31
31
  end
32
32
  end # :nodoc:
33
33
 
34
- attr_accessor :term # :nodoc:
34
+ attr_accessor :term, :opts # :nodoc:
35
35
 
36
- def initialize(term) # :nodoc:
36
+ def initialize(term, opts = {}) # :nodoc:
37
37
  @term = term.to_s.strip
38
+ @opts = opts
38
39
  end
39
40
 
40
41
  protected
@@ -117,13 +118,22 @@ module Municipitaly
117
118
 
118
119
  # returns an array of +Municipitaly::Municipality+ objects from a
119
120
  # <b>municipality name</b> term.
120
- # Term can be a partial string and is case insensitive.
121
+ # Term can be a partial string and is case insensitive.
122
+ # The optional parameter +greedy+ [boolean] permit to serch exact term
123
+ # name (if false) or partial word (true by default).
121
124
  #
122
125
  # example usage:
123
126
  # municipalities = Search.municipalities_from_name('monte')
127
+ # municipalities = Search.municipalities_from_name('monte', greedy: false)
124
128
  def municipalities_from_name # :doc:
129
+ greedy = opts.fetch(:greedy, true)
130
+ regexp = if greedy
131
+ Regexp.new(term, true)
132
+ else
133
+ Regexp.new("^#{term}$", true)
134
+ end
125
135
  data.municipalities.select do |m|
126
- m.name =~ Regexp.new(term, true)
136
+ m.name =~ regexp
127
137
  end
128
138
  end
129
139
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Municipitaly
4
4
  # :nodoc:
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.3'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: municipitaly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NatyDev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-09 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler