class HalcyonAPI::Region

Helper class for metadata pertaining to regions

@see developer.vainglorygame.com/docs#regions Vainglory API “Regions”

Constants

DB

Arrays of metadata about each region

SHORT_NAMES

Valid short names (na, eu, etc…) extracted from DB metadata

TYPES

Unique Region types (general, tournament, etc…) extracted from DB metadata

Attributes

name[R]

@return [String] the name of the region

short_name[R]

@return [String] the short name of the region

type[R]

@return [String] the type of region

Public Class Methods

[](identifier)
Alias for: new
detect_region_info(identifier) click to toggle source

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
find(identifier)
Alias for: new
new(identifier) click to toggle source

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
Also aliased as: find, []
valid_short_name?(short_name) click to toggle source

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

abbreviation() click to toggle source

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
eql?(other) click to toggle source

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