Class: WorldDb::Models::Country

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/worlddb/models/country.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_ary!(countries) ⇒ Object



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
92
93
94
# File 'lib/worlddb/models/country.rb', line 58

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_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

Returns:

  • (Boolean)


37
38
39
# File 'lib/worlddb/models/country.rb', line 37

def is_country?
  c? == true
end

#is_dependency?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/worlddb/models/country.rb', line 41

def is_dependency?
  d? == true
end

#is_supra?Boolean

NB: use is_ for flags to avoid conflict w/ assocs

Returns:

  • (Boolean)


33
34
35
# File 'lib/worlddb/models/country.rb', line 33

def is_supra?  
  s? == true
end

#parentObject

self referencing hierachy within countries e.g. EU > GB > EN



15
# File 'lib/worlddb/models/country.rb', line 15

belongs_to :parent,    :class_name => 'Country', :foreign_key => 'country_id'

#title_w_synonymsObject



47
48
49
50
51
52
53
54
55
# File 'lib/worlddb/models/country.rb', line 47

def title_w_synonyms
  return title if synonyms.blank?
  
  buf = ''
  buf << title
  buf << ' | '
  buf << synonyms.split('|').join(' | ')
  buf
end