class Novaposhta2::City
Represents a known city.
Public Class Methods
all()
click to toggle source
Returns list of all known cities.
# File lib/novaposhta2/city.rb, line 54 def all match(nil) end
find(name)
click to toggle source
Returns a city by name or part of the name. If more than one city match a name
- returns nil.
# File lib/novaposhta2/city.rb, line 46 def find(name) m = match(name) m.count == 1 ? m[0] : nil end
Also aliased as: []
find_by_ref(ref)
click to toggle source
Returns city matching ref
.
# File lib/novaposhta2/city.rb, line 35 def find_by_ref(ref) query(Ref: ref).first end
match(name)
click to toggle source
Returns all cities matching a pattern.
# File lib/novaposhta2/city.rb, line 40 def match(name) query(FindByString: name) end
new(params)
click to toggle source
# File lib/novaposhta2/city.rb, line 6 def initialize(params) @description = params['Description'] @description_ru = params['DescriptionRu'] @ref = params['Ref'] end
Private Class Methods
query(params)
click to toggle source
# File lib/novaposhta2/city.rb, line 61 def self.query(params) post('Address', 'getCities', params)['data'].map do |data| City.new(data) end end
Public Instance Methods
person(firstname, lastname, phone)
click to toggle source
Creates new person that belongs to the city.
# File lib/novaposhta2/city.rb, line 28 def person(firstname, lastname, phone) Person.new(self, firstname, lastname, phone) end
warehouses(number = nil)
click to toggle source
Lists all warehouses or returns warehouse by number.
# File lib/novaposhta2/city.rb, line 13 def warehouses(number = nil) @warehouses ||= post('Address', 'getWarehouses', CityRef: @ref)['data'].map do |data| Warehouse.new(data) end if number.nil? @warehouses else @warehouses.find {|w| w.number == number} end end
Also aliased as: []