Class: HalcyonAPI::Region
- Inherits:
-
Object
- Object
- HalcyonAPI::Region
- Defined in:
- lib/halcyon_api/region.rb
Overview
Helper class for metadata pertaining to regions
Constant Summary collapse
- DB =
Arrays of metadata about each region
[ ['general', 'na', 'North America'], ['general', 'eu', 'Europe'], ['general', 'sa', 'South America'], ['general', 'ea', 'East Asia'], ['general', 'sg', 'Southeast Asia (SEA)'], ['tournament', 'tournament-na', 'North America Tournaments'], ['tournament', 'tournament-eu', 'Europe Tournaments'], ['tournament', 'tournament-sa', 'South America Tournaments'], ['tournament', 'tournament-ea', 'East Asia Tournaments'], ['tournament', 'tournament-sg', 'Southeast Asia Tournaments'] ].freeze
- TYPES =
Unique Region types (general, tournament, etc…) extracted from DB metadata
DB.map { |region_data| region_data[0] }.uniq.freeze
- SHORT_NAMES =
Valid short names (na, eu, etc…) extracted from DB metadata
DB.map { |region_data| region_data[1] }.freeze
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the region.
-
#short_name ⇒ String
readonly
The short name of the region.
-
#type ⇒ String
readonly
The type of region.
Class Method Summary collapse
-
.detect_region_info(identifier) ⇒ Array?
Detects region data from DB constant.
-
.valid_short_name?(short_name) ⇒ Boolean
Checks if short name is known.
Instance Method Summary collapse
-
#abbreviation ⇒ String
Alias method for short name.
-
#eql?(other) ⇒ Boolean
Compares region to another region.
-
#initialize(identifier) ⇒ Region
constructor
A new instance of Region.
Constructor Details
#initialize(identifier) ⇒ Region
A new instance of Region.
44 45 46 47 48 49 50 51 |
# File 'lib/halcyon_api/region.rb', line 44 def initialize(identifier) data = self.class.detect_region_info(identifier) @type = data[0] @short_name = data[1] @name = data[2] rescue NoMethodError raise(RegionNameError, "Couldn't find region for '#{identifier}'") end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the region.
29 30 31 |
# File 'lib/halcyon_api/region.rb', line 29 def name @name end |
#short_name ⇒ String (readonly)
Returns the short name of the region.
32 33 34 |
# File 'lib/halcyon_api/region.rb', line 32 def short_name @short_name end |
#type ⇒ String (readonly)
Returns the type of region.
35 36 37 |
# File 'lib/halcyon_api/region.rb', line 35 def type @type end |
Class Method Details
.detect_region_info(identifier) ⇒ Array?
Detects region data from DB constant
96 97 98 |
# File 'lib/halcyon_api/region.rb', line 96 def detect_region_info(identifier) DB.detect { |region_data| region_data[1, 2].include?(identifier) } end |
.valid_short_name?(short_name) ⇒ Boolean
Checks if short name is known
84 85 86 |
# File 'lib/halcyon_api/region.rb', line 84 def valid_short_name?(short_name) SHORT_NAMES.include?(short_name) end |
Instance Method Details
#abbreviation ⇒ String
Alias method for short name
56 57 58 |
# File 'lib/halcyon_api/region.rb', line 56 def abbreviation @short_name end |
#eql?(other) ⇒ Boolean
Compares region to another region.
67 68 69 |
# File 'lib/halcyon_api/region.rb', line 67 def eql?(other) %i(name short_name type).all? { |a| send(a) == other.send(a) } end |