Class: ONIX::Territory
Instance Attribute Summary
Attributes included from Attributes
#attributes
Methods inherited from SubsetDSL
element, elements, #get_class, get_class, inherited, #initialize, n, #parse, ref_to_short, register_elements, register_scopes, #register_subset_array, registered_elements, #registered_elements, registered_scopes, scope, short_to_ref
Methods inherited from Subset
parse, #parse, #tag_match, #unsupported
Methods included from Attributes
attribute_class, #parse_attributes, #serialized_attributes
Class Method Details
.region_to_countries(region) ⇒ Array<String>
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/onix/territory.rb', line 49
def self.region_to_countries(region)
case region
when "WORLD"
CountryCode.list
when "ECZ"
["AT", "BE", "CY", "EE", "FI", "FR", "DE", "ES", "GR", "IE", "IT",
"LU", "MT", "NL", "PT", "SI", "SK", "AD", "MC", "SM", "VA", "ME"]
else
[]
end
end
|
.worldwide?(countries) ⇒ Boolean
Instance Method Details
#countries ⇒ Array<String>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/onix/territory.rb', line 13
def countries
countries = []
if @countries_included
countries += @countries_included.split(" ")
end
if @regions_included
countries += @regions_included.split(" ").map { |region| self.class.region_to_countries(region) }.flatten.uniq
end
if @countries_excluded
countries -= @countries_excluded.split(" ")
end
if @regions_excluded
countries -= @regions_excluded.split(" ").map { |region| self.class.region_to_countries(region) }.flatten.uniq
end
countries.uniq.sort
end
|
#countries=(v) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/onix/territory.rb', line 37
def countries= v
if (v.uniq & CountryCode.list).length == CountryCode.list.length
@regions_included = "WORLD"
else
@countries_included = v.uniq.join(" ")
end
end
|
#countries_excluded ⇒ String
6
|
# File 'lib/onix/territory.rb', line 6
element "CountriesExcluded", :text, :cardinality => 0..1
|
#countries_included ⇒ String
4
|
# File 'lib/onix/territory.rb', line 4
element "CountriesIncluded", :text, :cardinality => 0..1
|
#regions_excluded ⇒ String
7
|
# File 'lib/onix/territory.rb', line 7
element "RegionsExcluded", :text, :cardinality => 0..1
|
#regions_included ⇒ String
5
|
# File 'lib/onix/territory.rb', line 5
element "RegionsIncluded", :text, :cardinality => 0..1
|
#worldwide? ⇒ Boolean
32
33
34
|
# File 'lib/onix/territory.rb', line 32
def worldwide?
self.class.worldwide?(self.countries)
end
|