Class: ONIX::Territory
- Defined in:
- lib/onix/territory.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#countries ⇒ Object
all countries array.
- #countries=(v) ⇒ Object
-
#worldwide? ⇒ Boolean
has worldwide rights ?.
Methods inherited from SubsetDSL
_ancestor_registered_scopes, _ancestors_registered_elements, ancestor_registered_scopes, ancestors_registered_elements, element, elements, get_class, #initialize, #parse, ref_to_short, registered_elements, registered_scopes, scope, short_to_ref, #unsupported
Methods inherited from Subset
parse, #parse, tag_match, #tag_match, #unsupported
Constructor Details
This class inherits a constructor from ONIX::SubsetDSL
Class Method Details
.region_to_countries(region) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/onix/territory.rb', line 40 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
52 53 54 |
# File 'lib/onix/territory.rb', line 52 def self.worldwide?(countries) (countries & CountryCode.list).length==CountryCode.list.length end |
Instance Method Details
#countries ⇒ Object
all countries array
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/onix/territory.rb', line 10 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
32 33 34 35 36 37 38 |
# File 'lib/onix/territory.rb', line 32 def countries=v if (v.uniq & CountryCode.list).length==CountryCode.list.length @regions_included="WORLD" else @countries_included=v.uniq.join(" ") end end |
#worldwide? ⇒ Boolean
has worldwide rights ?
28 29 30 |
# File 'lib/onix/territory.rb', line 28 def worldwide? self.class.worldwide?(self.countries) end |