Class: VaingloryAPI::Region
- Inherits:
-
Object
- Object
- VaingloryAPI::Region
- Defined in:
- lib/vainglory_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
-
.find(identifier) ⇒ Region
(also: [])
Find a region by name or abbreviation (“short name”).
-
.valid_short_name?(short_name) ⇒ Boolean
Checks if short name is known.
-
.validate_short_name!(short_name) ⇒ True
Validates a short name.
Instance Method Summary collapse
-
#abbreviation ⇒ String
Alias method for short name.
-
#eql?(other) ⇒ Boolean
Compares region to another region.
-
#initialize(type, short_name, name) ⇒ Region
constructor
A new instance of Region.
Constructor Details
#initialize(type, short_name, name) ⇒ Region
Instantiation is private
A new instance of Region.
44 45 46 47 48 |
# File 'lib/vainglory_api/region.rb', line 44 def initialize(type, short_name, name) @type = type @short_name = short_name @name = name end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the region.
29 30 31 |
# File 'lib/vainglory_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/vainglory_api/region.rb', line 32 def short_name @short_name end |
#type ⇒ String (readonly)
Returns the type of region.
35 36 37 |
# File 'lib/vainglory_api/region.rb', line 35 def type @type end |
Class Method Details
.find(identifier) ⇒ Region Also known as: []
Find a region by name or abbreviation (“short name”)
83 84 85 |
# File 'lib/vainglory_api/region.rb', line 83 def find(identifier) new(*find_region_data(identifier)) rescue name_error(identifier) end |
.valid_short_name?(short_name) ⇒ Boolean
Checks if short name is known
95 96 97 |
# File 'lib/vainglory_api/region.rb', line 95 def valid_short_name?(short_name) SHORT_NAMES.include?(short_name) end |
.validate_short_name!(short_name) ⇒ True
Validates a short name
107 108 109 |
# File 'lib/vainglory_api/region.rb', line 107 def validate_short_name!(short_name) valid_short_name?(short_name) or name_error(short_name) end |
Instance Method Details
#abbreviation ⇒ String
Alias method for short name
53 54 55 |
# File 'lib/vainglory_api/region.rb', line 53 def abbreviation @short_name end |
#eql?(other) ⇒ Boolean
Compares region to another region.
64 65 66 |
# File 'lib/vainglory_api/region.rb', line 64 def eql?(other) %i(name short_name type).all? { |a| send(a) == other.send(a) } end |