Class: WorldDB::Models::Country
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WorldDB::Models::Country
- Defined in:
- lib/worlddb/models/country.rb
Class Method Summary collapse
Instance Method Summary collapse
- #is_country? ⇒ Boolean
- #is_dependency? ⇒ Boolean
-
#is_supra? ⇒ Boolean
NB: use is_ for flags to avoid conflict w/ assocs.
-
#parent ⇒ Object
self referencing hierachy within countries e.g.
- #title_w_synonyms ⇒ Object
Class Method Details
.create_from_ary!(countries) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/worlddb/models/country.rb', line 55 def self.create_from_ary!( countries ) countries.each do |values| ## key & title required attr = { :key => values[0], :title => values[1], :code => values[2] } value_numbers = [] ## check for optional values values[3..-1].each do |value| if value.is_a? Numeric value_numbers << value elsif value =~ /^motor:/ value_motor = value[6..-1] ## cut off region: motor attr[ :motor ] = value_motor elsif value =~ /^tags:/ = value[5..-1] ## cut off tags: prefix # do nothing now else # issue warning: unknown type for value end end if value_numbers.size > 0 attr[ :area ] = value_numbers[0] # NB: area for countries goes first attr[ :pop ] = value_numbers[1] end Country.create!( attr ) end # each country end |
Instance Method Details
#is_country? ⇒ Boolean
34 35 36 |
# File 'lib/worlddb/models/country.rb', line 34 def is_country? c? == true end |
#is_dependency? ⇒ Boolean
38 39 40 |
# File 'lib/worlddb/models/country.rb', line 38 def is_dependency? d? == true end |
#is_supra? ⇒ Boolean
NB: use is_ for flags to avoid conflict w/ assocs
30 31 32 |
# File 'lib/worlddb/models/country.rb', line 30 def is_supra? s? == true end |
#parent ⇒ Object
self referencing hierachy within countries e.g. EU > GB > EN
12 |
# File 'lib/worlddb/models/country.rb', line 12 belongs_to :parent, :class_name => 'Country', :foreign_key => 'country_id' |
#title_w_synonyms ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/worlddb/models/country.rb', line 44 def title_w_synonyms return title if synonyms.blank? buf = '' buf << title buf << ' | ' buf << synonyms.split('|').join(' | ') buf end |