Class: EgovUtils::Address
Defined Under Namespace
Classes: Country, District, Region
Constant Summary
collapse
- CZ_ISO_CODE =
'203'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.countries ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'app/models/egov_utils/address.rb', line 24
def self.countries
return @countries if @countries
require 'csv'
@countries = []
CSV.foreach(EgovUtils::Engine.root.join('config', 'countries.csv'), col_sep: ';', headers: true) do |row|
@countries << Country.new( row[0], row[1], row[2], row[3]) if row[1]
end
@countries
end
|
.districts ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'app/models/egov_utils/address.rb', line 34
def self.districts
return @districts if @districts
require 'csv'
@districts = []
CSV.foreach(EgovUtils::Engine.root.join('config', 'okres.csv'), col_sep: ';', headers: true) do |row|
@districts << District.new( row[0].to_i, row[1], row[2].to_i) if row[1]
end
@districts
end
|
.region_for_district(district_name) ⇒ Object
54
55
56
57
|
# File 'app/models/egov_utils/address.rb', line 54
def self.region_for_district(district_name)
district = districts.detect{|d| d[:name] == district_name }
regions.detect{|r| r[:id] == district[:region_id] } if district
end
|
.regions ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'app/models/egov_utils/address.rb', line 44
def self.regions
return @regions if @regions
require 'csv'
@regions = []
CSV.foreach(EgovUtils::Engine.root.join('config', 'kraj.csv'), col_sep: ';', headers: true) do |row|
@regions << Region.new( row[0].to_i, row[1]) if row[1]
end
@regions
end
|
Instance Method Details
#country_ids ⇒ Object
69
70
71
|
# File 'app/models/egov_utils/address.rb', line 69
def country_ids
self.class.countries.collect{|r| r[:iso_id]}
end
|
#district=(value) ⇒ Object
74
75
76
77
|
# File 'app/models/egov_utils/address.rb', line 74
def district=(value)
self.region = self.class.region_for_district(value).try(:[], :name)
super
end
|
#district_names ⇒ Object
63
64
65
|
# File 'app/models/egov_utils/address.rb', line 63
def district_names
self.class.districts.collect{|r| r[:name]}
end
|
#from_egon_info(message) ⇒ Object
104
105
106
107
108
109
110
111
112
113
|
# File 'app/models/egov_utils/address.rb', line 104
def from_egon_info(message)
self.egov_identifier = message[:adresni_misto_kod]
self.district = message[:okres_nazev]
self.city = message[:obec_nazev]
self.city_part = message[:cast_obce_nazev]
self.street = message[:ulice_nazev]
self.postcode = message[:posta_kod]
self.house_number = message[:cislo_domovni]
self.orientation_number = message[:cislo_orientacni]+(message[:cislo_orientacni_pismeno] || '')
end
|
#full_address ⇒ Object
87
88
89
|
# File 'app/models/egov_utils/address.rb', line 87
def full_address
to_s
end
|
#in_czech_republic? ⇒ Boolean
59
60
61
|
# File 'app/models/egov_utils/address.rb', line 59
def in_czech_republic?
country == CZ_ISO_CODE || country.nil?
end
|
#number ⇒ Object
79
80
81
82
83
84
85
|
# File 'app/models/egov_utils/address.rb', line 79
def number
if !house_number.blank? && !orientation_number.blank?
"#{house_number}/#{orientation_number}"
else
house_number.presence || orientation_number.presence
end
end
|
#prepare_egon_message(message) ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'app/models/egov_utils/address.rb', line 95
def prepare_egon_message(message)
message.obec_nazev = city.presence
message.cast_obce_nazev = city_part.presence
message.ulice_nazev = street.presence
message.posta_kod = postcode.presence
message.cislo_domovni = house_number.presence
message.cislo_orientacni = orientation_number.presence
end
|
#region_names ⇒ Object
66
67
68
|
# File 'app/models/egov_utils/address.rb', line 66
def region_names
self.class.regions.collect{|r| r[:name]}
end
|
#to_s ⇒ Object
91
92
93
|
# File 'app/models/egov_utils/address.rb', line 91
def to_s
"#{street} #{number}, #{postcode} #{city}"
end
|