module Ratsit::Filter
Constants
- FILTER_AB
Company filters
- FILTER_ADDRESS
- FILTER_AGE_FROM
- FILTER_AGE_TO
- FILTER_CITY
- FILTER_COMPANY_ENGAGEMENT
- FILTER_COMPANY_NAME
- FILTER_COMPANY_TYPE
- FILTER_EF
- FILTER_FEMALE
- FILTER_FIRST_NAME
- FILTER_HB
- FILTER_HB_KB
- FILTER_IDS
- FILTER_KB
- FILTER_LAST_NAME
- FILTER_MALE
- FILTER_MARRIED
Person filters
- FILTER_MUNICIPALITY
- FILTER_NO_COMPANY_ENGAGEMENT
- FILTER_NUMBER_OF_HITS
- FILTER_ORG_NR
- FILTER_OTHER
- FILTER_PACKAGES
- FILTER_PACKAGE_LARGE
- FILTER_PACKAGE_MEDIUM
- FILTER_PACKAGE_REMARK
- FILTER_PACKAGE_SMALL_1
- FILTER_PACKAGE_SMALL_2
- FILTER_PACKAGE_SMALL_3
- FILTER_PHONE
- FILTER_PNR
- FILTER_SEARCH_AGE
- FILTER_SSN
- FILTER_TOKEN
token filters
- FILTER_UNMARRIED
- FILTER_USE_PHONETIC_SEARCH
- FILTER_ZIP_CODE
Private Instance Methods
parse_age(arg)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 137 def parse_age(arg) if arg.is_a?(String) if !(arg =~ /^[0-9]+$/) raise RatsitFilterError, 'Invalid age in filter' end larg = arg.to_i elsif arg.is_a?(Integer) larg = arg else raise RatsitFilterError, 'Invalid arg type in filter' end # ratsit specifies these ages. if larg < 0 || larg > 150 raise RatsitFilterError, 'Invalid age' end "#{larg}" end
parse_bool(arg)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 122 def parse_bool(arg) return arg if arg.is_a?(TrueClass) || arg.is_a?(FalseClass) raise RatsitFilterError, 'Invalid bool representation' if !arg.is_a?(String) return true if arg.downcase == 'true' return false if arg.downcase == 'false' raise RatsitFilterError, 'Invalid textual bool value' end
parse_bool_string(arg)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 130 def parse_bool_string(arg) return arg if arg == 'true' || arg == 'false' return 'true' if arg.is_a?(TrueClass) return 'false' if arg.is_a?(FalseClass) raise RatsitFilterError, 'Invalid string representation of bool' end
parse_int(arg)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 155 def parse_int(arg) return arg if arg.is_a?(Integer) return arg.to_i if arg =~ /^[0-9]+$/ raise RatsitFilterError, 'Invalid integer' end
parse_list(arg)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 161 def parse_list(arg) return arg.join(',') if arg.is_a?(Array) return arg if arg.is_a?(String) raise RatsitFilterError, 'Invalid array' end
parse_string(arg)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 117 def parse_string(arg) return arg if arg.is_a?(String) raise RatsitFilterError, 'Invalid string' end
validate_company_types(lst)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 181 def validate_company_types(lst) return validate_list(lst, [FILTER_AB, FILTER_EF, FILTER_HB_KB, FILTER_OTHER]) end
validate_filters(filter_defaults={}, filters={})
click to toggle source
# File lib/ratsit/filter/filter.rb, line 189 def validate_filters(filter_defaults={}, filters={}) if !filters.is_a?(Hash) filters = {} end filters.reject! { |k,_| !filter_defaults.keys.include? k } filter_defaults.each do |filter_name, defs| if !filters.keys.include? filter_name filters[filter_name] = defs[:default] end filters[filter_name] = defs[:parse].call(filters[filter_name]) if defs.has_key?(:validate) filters[filter_name] = defs[:validate].call(filters[filter_name]) end end if filters.keys.include?(FILTER_AGE_TO) && filters.keys.include?(FILTER_AGE_FROM) if filters[FILTER_AGE_TO].to_i < filters[FILTER_AGE_FROM].to_i raise RatsitFilterError, 'Invalid age span' end end filters end
validate_list(lst, accepted_values=[])
click to toggle source
# File lib/ratsit/filter/filter.rb, line 167 def validate_list(lst, accepted_values=[]) if lst.is_a?(Array) arr = lst elsif lst.is_a?(String) arr = lst.split(',').map(&:strip) end err = [] arr.each { |v| err.push(v) if !accepted_values.include?(v) } if err.length > 0 raise RatsitFilterError, "Invalid list values: #{err.join(',')}" end arr.join(',') end
validate_package_types(lst)
click to toggle source
# File lib/ratsit/filter/filter.rb, line 185 def validate_package_types(lst) return validate_list(lst, [FILTER_PACKAGE_SMALL_1, FILTER_PACKAGE_SMALL_2, FILTER_PACKAGE_SMALL_3, FILTER_PACKAGE_REMARK, FILTER_PACKAGE_MEDIUM, FILTER_PACKAGE_LARGE]) end