openkvk 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.
- data/lib/openkvk/version.rb +1 -1
- data/lib/openkvk.rb +23 -5
- data/spec/openkvk_spec.rb +2 -2
- metadata +2 -2
data/lib/openkvk/version.rb
CHANGED
data/lib/openkvk.rb
CHANGED
@@ -7,7 +7,7 @@ module OpenKVK
|
|
7
7
|
class << self
|
8
8
|
def find(options={})
|
9
9
|
if options.is_a?(String)
|
10
|
-
options = {:conditions => ["bedrijfsnaam
|
10
|
+
options = {:conditions => ["bedrijfsnaam LIKE '%#{options}%'", "bedrijfsnaam LIKE '%#{options.to_s.upcase}%'", "bedrijfsnaam LIKE '%#{capitalize_and_format_each_word(options)}%'"], :match_condition => :any}
|
11
11
|
end
|
12
12
|
options = {:limit => 1000, :select => ["*"], :count => :all, :match_condition => :all}.merge(options)
|
13
13
|
|
@@ -17,15 +17,33 @@ module OpenKVK
|
|
17
17
|
result
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def find_by_bedrijfsnaam(name, options={})
|
21
|
+
# bedrijfsnaam is always a string, so we want to search for different formats of the string
|
22
|
+
options = {:conditions => ["bedrijfsnaam LIKE '%#{name}%'", "bedrijfsnaam LIKE '%#{name.to_s.upcase}%'", "bedrijfsnaam LIKE '%#{capitalize_and_format_each_word(name)}%'"], :match_condition => :any}.merge(options)
|
23
|
+
find(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
%w{kvk kvks adres postcode plaats type website}.each do |field|
|
21
27
|
define_method("find_by_#{field}") do |value, options={}|
|
22
28
|
options = {:conditions => ["#{field} ILIKE '%#{value}%'"]}.merge(options)
|
23
29
|
find(options)
|
24
30
|
end
|
25
31
|
end
|
32
|
+
|
33
|
+
private
|
26
34
|
|
27
|
-
|
28
|
-
|
35
|
+
def capitalize_and_format_each_word(name)
|
36
|
+
# capitalize each word
|
37
|
+
name.gsub!(/\b('?[a-z])/) do |word|
|
38
|
+
$1.capitalize
|
39
|
+
end
|
29
40
|
|
41
|
+
# format B.V. and N.V.
|
42
|
+
name.gsub!(/([b|n]\.?v\.?)$/i) do |match|
|
43
|
+
"#{match.to_s[0].upcase}.V."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
30
48
|
|
31
|
-
end
|
49
|
+
end
|
data/spec/openkvk_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe OpenKVK do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should find multiple companies" do
|
20
|
-
expect_query("SELECT * FROM kvk WHERE bedrijfsnaam
|
20
|
+
expect_query("SELECT * FROM kvk WHERE bedrijfsnaam LIKE '%Zilverline%' OR bedrijfsnaam LIKE '%ZILVERLINE%' OR bedrijfsnaam LIKE '%%' LIMIT 1000", '[{"RESULT":{"TYPES":["bigint","varchar","int","int","varchar","varchar","varchar","varchar","varchar"],"HEADER":["kvk","bedrijfsnaam","kvks","sub","adres","postcode","plaats","type","website"],"ROWS":[["342838240000","Zilverline Beheer B.V.","34283824","0","Finsenstraat 56","1098RJ","Amsterdam","Hoofdvestiging",null],["343774520000","Zilverline B.V.","34377452","0","Molukkenstraat 200 E4","1098TW","Amsterdam","Hoofdvestiging",null]]}}]')
|
21
21
|
|
22
22
|
companies = OpenKVK.find("Zilverline")
|
23
23
|
companies.size.should == 2
|
@@ -63,7 +63,7 @@ describe OpenKVK do
|
|
63
63
|
|
64
64
|
describe ".find_by_bedrijfsnaam" do
|
65
65
|
it "should find a company" do
|
66
|
-
expect_query("SELECT * FROM kvk WHERE bedrijfsnaam
|
66
|
+
expect_query("SELECT * FROM kvk WHERE bedrijfsnaam LIKE '%Zilverline B.V.%' OR bedrijfsnaam LIKE '%ZILVERLINE B.V.%' OR bedrijfsnaam LIKE '%Zilverline B.V.%' LIMIT 1", '[{"RESULT":{"TYPES":["bigint","varchar","int","int","varchar","varchar","varchar","varchar","varchar"],"HEADER":["kvk","bedrijfsnaam","kvks","sub","adres","postcode","plaats","type","website"],"ROWS":[["343774520000","Zilverline B.V.","34377452","0","Molukkenstraat 200 E4","1098TW","Amsterdam","Hoofdvestiging",null]]}}]')
|
67
67
|
|
68
68
|
OpenKVK.find_by_bedrijfsnaam("Zilverline B.V.", :count => :first).bedrijfsnaam.should == "Zilverline B.V."
|
69
69
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: openkvk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel van Hoesel
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-27 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|