Class: Spree::Country
- Inherits:
-
Object
- Object
- Spree::Country
- Defined in:
- app/models/spree/country.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#current_market ⇒ Spree::Market?
Lookups Market for Country for the current Store.
- #default?(store = nil) ⇒ Boolean
-
#default_currency ⇒ Object
Returns the default currency code for this country (e.g., ‘USD’, ‘EUR’) Uses the countries gem (ISO3166) for accurate currency data.
-
#default_locale ⇒ Object
Returns the default locale/language for this country (e.g., ‘en’, ‘de’) Uses the countries gem (ISO3166) for accurate language data.
- #to_s ⇒ Object
Class Method Details
.by_iso(iso) ⇒ Object
21 22 23 |
# File 'app/models/spree/country.rb', line 21 def self.by_iso(iso) where(['LOWER(iso) = ?', iso.downcase]).or(where(['LOWER(iso3) = ?', iso.downcase])).take end |
.iso_to_emoji_flag(iso) ⇒ Object
39 40 41 |
# File 'app/models/spree/country.rb', line 39 def self.iso_to_emoji_flag(iso) iso.upcase.chars.map { |c| (c.ord + 127397).chr(Encoding::UTF_8) }.join end |
.to_tom_select_json ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/models/spree/country.rb', line 30 def self.to_tom_select_json pluck(:name, :id, :iso).map do |name, id, iso| { id: id, name: "#{iso_to_emoji_flag(iso)} #{name}" } end.as_json end |
Instance Method Details
#<=>(other) ⇒ Object
49 50 51 |
# File 'app/models/spree/country.rb', line 49 def <=>(other) name <=> other.name end |
#current_market ⇒ Spree::Market?
Lookups Market for Country for the current Store
45 46 47 |
# File 'app/models/spree/country.rb', line 45 def current_market @current_market ||= Spree::Current.store&.market_for_country(self) end |
#default?(store = nil) ⇒ Boolean
25 26 27 28 |
# File 'app/models/spree/country.rb', line 25 def default?(store = nil) store ||= Spree::Store.default self == store.default_country end |
#default_currency ⇒ Object
Returns the default currency code for this country (e.g., ‘USD’, ‘EUR’) Uses the countries gem (ISO3166) for accurate currency data
59 60 61 |
# File 'app/models/spree/country.rb', line 59 def default_currency iso3166_country&.currency_code end |
#default_locale ⇒ Object
Returns the default locale/language for this country (e.g., ‘en’, ‘de’) Uses the countries gem (ISO3166) for accurate language data
65 66 67 |
# File 'app/models/spree/country.rb', line 65 def default_locale iso3166_country&.languages&.first end |
#to_s ⇒ Object
53 54 55 |
# File 'app/models/spree/country.rb', line 53 def to_s name end |