Class: Country

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

Constant Summary

USA_ID =
214
CANADA_ID =
35
ACTIVE_COUNTRY_IDS =
[CANADA_ID, USA_ID]

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) active



39
40
41
# File 'app/models/country.rb', line 39

def self.active
  where(:active => true)
end

+ (Array) form_selector

Finds all the countries for a form select .

Parameters:

  • none

Returns:

  • (Array)

    an array of arrays with [string, country.id]



46
47
48
49
50
51
# File 'app/models/country.rb', line 46

def self.form_selector
  Rails.cache.fetch("Country-form_selector") do
    data = Country.where(:active => true).order('abbreviation ASC').all().map { |c| [c.abbrev_and_name, c.id] }
    data.blank? ? [[]] : data
  end
end

Instance Method Details

- (String) abbrev_and_name

Call this method to display the country_abbreviation - country

Examples:

abbreviation == USA, country == 'United States'

country.abbrev_and_name => 'USA - United States'

Parameters:

  • none

Returns:

  • (String)

    country abbreviation - country name



35
36
37
# File 'app/models/country.rb', line 35

def abbrev_and_name
  abbreviation_name
end

- (String) abbreviation_name(append_name = "")

Call this method to display the country_abbreviation - country with and appending name

Examples:

abbreviation == USA, country == 'United States'

country.abbreviation_name(': capitalist') => 'USA - United States : capitalist'

Parameters:

  • (append name, optional)

Returns:

  • (String)

    country abbreviation - country name



24
25
26
# File 'app/models/country.rb', line 24

def abbreviation_name(append_name = "")
  ([abbreviation, name].join(" - ") + " #{append_name}").strip
end