Class: Trackdown::Providers::BaseProvider
- Inherits:
-
Object
- Object
- Trackdown::Providers::BaseProvider
- Defined in:
- lib/trackdown/providers/base_provider.rb
Direct Known Subclasses
Class Method Summary collapse
-
.available?(request: nil) ⇒ Boolean
Returns true if this provider can handle the given request/context.
-
.get_country_name(country_code) ⇒ Object
Helper to extract country name from country code using countries gem.
-
.get_emoji_flag(country_code) ⇒ Object
Helper to get emoji flag from country code.
-
.locate(ip, request: nil) ⇒ LocationResult
Locates the IP and returns a LocationResult.
Class Method Details
.available?(request: nil) ⇒ Boolean
Returns true if this provider can handle the given request/context
9 10 11 |
# File 'lib/trackdown/providers/base_provider.rb', line 9 def self.available?(request: nil) raise NotImplementedError, "#{self} must implement .available?" end |
.get_country_name(country_code) ⇒ Object
Helper to extract country name from country code using countries gem
29 30 31 32 33 34 35 36 |
# File 'lib/trackdown/providers/base_provider.rb', line 29 def self.get_country_name(country_code) return 'Unknown' unless country_code country = ISO3166::Country.new(country_code) country&.iso_short_name || country&.name || 'Unknown' rescue StandardError 'Unknown' end |
.get_emoji_flag(country_code) ⇒ Object
Helper to get emoji flag from country code
24 25 26 |
# File 'lib/trackdown/providers/base_provider.rb', line 24 def self.get_emoji_flag(country_code) country_code ? country_code.tr('A-Z', "\u{1F1E6}-\u{1F1FF}") : "🏳️" end |
.locate(ip, request: nil) ⇒ LocationResult
Locates the IP and returns a LocationResult
17 18 19 |
# File 'lib/trackdown/providers/base_provider.rb', line 17 def self.locate(ip, request: nil) raise NotImplementedError, "#{self} must implement .locate" end |