Module: OpenKVK

Extended by:
Configuration
Defined in:
lib/openkvk.rb,
lib/openkvk/api.rb,
lib/openkvk/version.rb,
lib/openkvk/configuration.rb

Defined Under Namespace

Modules: Configuration Classes: API, InvalidResponseException

Constant Summary collapse

VERSION =
"0.0.8"

Constants included from Configuration

Configuration::DEFAULT_HOST, Configuration::VALID_OPTIONS_KEYS

Class Method Summary collapse

Methods included from Configuration

configure, extended, options, reset

Class Method Details

.find(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/openkvk.rb', line 14

def find(options={})
  if options.is_a?(String)
    options = {:conditions => ["bedrijfsnaam LIKE '%#{options}%'", "bedrijfsnaam LIKE '%#{options.to_s.upcase}%'", "bedrijfsnaam LIKE '%#{capitalize_and_format_each_word(options)}%'"], :match_condition => :any}
  end
  options = {:limit => 1000, :select => ["*"], :count => :all, :match_condition => :all}.merge(options)
  
  options[:limit] = 1 if options[:count] == :first
  result = API.query("SELECT #{options[:select].join(", ")} FROM kvk WHERE #{options[:conditions].join(options[:match_condition] == :any ? " OR " : " AND ")} LIMIT #{options[:limit]}")
  return result.first if options[:count] == :first
  result
end

.find_by_bedrijfsnaam(name, options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/openkvk.rb', line 26

def find_by_bedrijfsnaam(name, options={})
  # bedrijfsnaam is always a string, so we want to search for different formats of the string
  options = {:conditions => ["bedrijfsnaam LIKE '%#{name}%'", "bedrijfsnaam LIKE '%#{name.to_s.upcase}%'", "bedrijfsnaam LIKE '%#{capitalize_and_format_each_word(name)}%'"], :match_condition => :any}.merge(options)
  find(options)
end

.search(keywords) ⇒ Object



9
10
11
12
# File 'lib/openkvk.rb', line 9

def search(keywords)
  numbers = API.search(keywords)
  numbers.size > 0 ? API.query("SELECT * FROM kvk WHERE kvk IN (#{numbers.join(", ")})") : []
end