class Fias::Query::Params
Constants
- KEYS
Attributes
forms[R]
params[R]
sanitized[R]
split[R]
synonyms[R]
Public Class Methods
new(params)
click to toggle source
# File lib/fias/query/params.rb, line 6 def initialize(params) @params = params @params.assert_valid_keys(*KEYS) extract_names remove_duplicates move_federal_city_to_correct_place strip_house_number sort extract_synonyms split_sanitized fill_forms end
Private Instance Methods
extract_names()
click to toggle source
# File lib/fias/query/params.rb, line 26 def extract_names extracted = @params.map do |name, value| if value.is_a?(Array) [name, value] else next if value.blank? || !value.is_a?(String) [name, Fias::Name::Extract.extract(value)] end end @sanitized = Hash[*extracted.compact.flatten(1)] end
extract_synonyms()
click to toggle source
# File lib/fias/query/params.rb, line 79 def extract_synonyms @synonyms = map_sanitized { |value| Fias::Name::Synonyms.expand(value) } end
fill_forms()
click to toggle source
# File lib/fias/query/params.rb, line 87 def fill_forms @forms = map_sanitized { |value| Fias::Name::Synonyms.forms(value) } end
find_federal_city()
click to toggle source
# File lib/fias/query/params.rb, line 60 def find_federal_city @sanitized.values.find do |value| value.is_a?(Array) && Fias::FEDERAL_CITIES.include?(value.first) end end
map_sanitized() { |first| ... }
click to toggle source
# File lib/fias/query/params.rb, line 91 def map_sanitized(&block) mapped = @sanitized.map do |key, value| [key, yield(value.first)] end Hash[mapped] end
move_federal_city_to_correct_place()
click to toggle source
# File lib/fias/query/params.rb, line 45 def move_federal_city_to_correct_place federal_city = find_federal_city return unless federal_city @sanitized[:subcity] = city if city && city[0] != federal_city[0] if federal_city[1].blank? federal_city += Fias::Name::Canonical.canonical('г.') end @sanitized[:city] = federal_city @sanitized.delete(:district) @sanitized.delete(:region) end
remove_duplicates()
click to toggle source
# File lib/fias/query/params.rb, line 39 def remove_duplicates @sanitized.delete(:region) if region == city @sanitized.delete(:district) if [region, city].include?(district) @sanitized.delete(:street) if street == district end
sort()
click to toggle source
# File lib/fias/query/params.rb, line 71 def sort sanitized = KEYS.map do |key| value = @sanitized[key] [key, value] if value.present? end @sanitized = Hash[sanitized.compact] end
split_sanitized()
click to toggle source
# File lib/fias/query/params.rb, line 83 def split_sanitized @split = map_sanitized { |value| Fias::Name::Split.split(value) } end
strip_house_number()
click to toggle source
# File lib/fias/query/params.rb, line 66 def strip_house_number return if street.blank? @sanitized[:street] = Fias::Name::HouseNumber.extract(street).first end