class HalcyonAPI::Region
Helper class for metadata pertaining to regions
@see developer.vainglorygame.com/docs#regions Vainglory API “Regions”
Constants
Attributes
@return [String] the name of the region
@return [String] the short name of the region
@return [String] the type of region
Public Class Methods
Detects region data from DB
constant
@example Detecting region data from DB
HalcyonAPI::Region.detech_region_info('na')
@param [String] identifier the name or short name of the desired region @return [Array] if region data is found @return [nil] if region data is not found @see DB
# File lib/halcyon_api/region.rb, line 96 def detect_region_info(identifier) DB.detect { |region_data| region_data[1, 2].include?(identifier) } end
A new instance of Region
.
@param (String) identifier the name or short name of a region @return [Region] a new instance of a Region
@raise [HalcyonAPI::RegionNameError] if the identifier is not found @see SHORT_NAMES
@see DB
# 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
Checks if short name is known
@example Checking if a short name is valid
HalcyonAPI::Region.valid_short_name?('na') # => true HalcyonAPI::Region.valid_short_name?('QQ') # => false
@param [String] short_name
the short name of a desired region @return [Boolean] whether the short name is known @see SHORT_NAMES
@see DB
# File lib/halcyon_api/region.rb, line 84 def valid_short_name?(short_name) SHORT_NAMES.include?(short_name) end
Public Instance Methods
Alias method for short name
@return [String] the “short name” of the region
# File lib/halcyon_api/region.rb, line 56 def abbreviation @short_name end
Compares region to another region.
@example Compare two regions
HalcyonAPI::Region['na'].eql? VaingloryAPI::Region['na'] # => true HalcyonAPI::Region['na'].eql? VaingloryAPI::Region['sg'] # => false
@param [VaingloryAPU::Region] other another region to compare for quality @return [Boolean] whether all attributes match
# File lib/halcyon_api/region.rb, line 67 def eql?(other) %i(name short_name type).all? { |a| send(a) == other.send(a) } end