Class: Country
- Inherits:
-
Pattana::ApplicationRecord
- Object
- ActiveRecord::Base
- Pattana::ApplicationRecord
- Country
- Defined in:
- app/models/country.rb
Class Method Summary collapse
-
.save_row_data(hsh) ⇒ Object
Import Methods.
Instance Method Summary collapse
- #can_be_deleted? ⇒ Boolean
-
#can_be_edited? ⇒ Boolean
Permission Methods ——————.
-
#display_name ⇒ Object
-
Return full name == Examples >>> country.display_name => “India”.
-
-
#display_operational ⇒ Object
-
Return Yes or No == Examples >>> country.display_operational => “Yes”.
-
-
#display_show_in_api ⇒ Object
-
Return Yes or No == Examples >>> country.display_show_in_api => “No”.
-
Class Method Details
.save_row_data(hsh) ⇒ Object
Import Methods
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 |
# File 'app/models/country.rb', line 35 def self.save_row_data(hsh) return if hsh[:name].blank? iso_alpha_2 = self.clean_string(hsh[:iso_alpha_2]) country = Country.where("iso_alpha_2 = ?", iso_alpha_2).first || Country.new(iso_alpha_2: iso_alpha_2) country.name = self.clean_string(hsh[:name]) if hsh[:name] country.iso_name = self.clean_string(hsh[:iso_name]) if hsh[:iso_name] country.official_name = self.clean_string(hsh[:official_name]) if hsh[:official_name] country.iso_alpha_3 = self.clean_string(hsh[:iso_alpha_3]) if hsh[:iso_alpha_3] country.itu_code = self.clean_string(hsh[:itu_code]) if hsh[:itu_code] country.dialing_prefix = self.clean_string(hsh[:dialing_prefix].to_s) if hsh[:dialing_prefix] country.fips = self.clean_string(hsh[:fips]) if hsh[:fips] country.currency_code = self.clean_string(hsh[:currency_code]) if hsh[:currency_code] country.currency_name = self.clean_string(hsh[:currency_name]) if hsh[:currency_name] country.is_independent = self.clean_string(hsh[:is_independent]) if hsh[:is_independent] country.capital = self.clean_string(hsh[:capital]) if hsh[:capital] country.continent = self.clean_string(hsh[:continent]) if hsh[:continent] country.tld = self.clean_string(hsh[:tld]) if hsh[:tld] country.languages = self.clean_string(hsh[:languages]) if hsh[:languages] country.latitude = self.clean_string(hsh[:latitude]) if hsh[:latitude] && hsh[:latitude] != "NULL" country.longitude = self.clean_string(hsh[:longitude]) if hsh[:longitude] && hsh[:longitude] != "NULL" country.show_in_api = true if hsh[:show_in_api] && ["t", "true", "yes", "y"].include?(self.clean_string(hsh[:show_in_api]).downcase) # Initializing error hash for displaying all errors altogether error_object = Kuppayam::Importer::ErrorHash.new if country.valid? begin country.save! rescue Exception => e summary = "uncaught #{e} exception while handling connection: #{e.}" details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}" error_object.errors << { summary: summary, details: details } end else summary = "Error while saving country: #{country.name}" details = "Error! #{country.errors..to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_deleted? ⇒ Boolean
94 95 96 97 98 |
# File 'app/models/country.rb', line 94 def can_be_deleted? return false if self.regions.any? || self.cities.any? return false if operational? true end |
#can_be_edited? ⇒ Boolean
Permission Methods
90 91 92 |
# File 'app/models/country.rb', line 90 def can_be_edited? true end |
#display_name ⇒ Object
-
Return full name
Examples
>>> country.display_name
=> "India"
107 108 109 |
# File 'app/models/country.rb', line 107 def display_name self.name end |
#display_operational ⇒ Object
-
Return Yes or No
Examples
>>> country.display_operational
=> "Yes"
123 124 125 |
# File 'app/models/country.rb', line 123 def display_operational self.operational ? "Yes" : "No" end |
#display_show_in_api ⇒ Object
-
Return Yes or No
Examples
>>> country.display_show_in_api
=> "No"
115 116 117 |
# File 'app/models/country.rb', line 115 def display_show_in_api self.show_in_api ? "Yes" : "No" end |