class VaingloryAPI::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: find
find(identifier) click to toggle source

Find a region by name or abbreviation (“short name”)

@example Finding a region

VaingloryAPI::Region.find('eu')

@example Finding a region (alternative syntax)

VaingloryAPI::Region['eu'] # => <VaingloryAPI::Region ...>

@param [String] identifier the target name or abbreviation of the region @return [Region] if the identifier is found @raise [VaingloryAPI::RegionNameError] if the identifier is not found @see DB @see SHORT_NAMES

# File lib/vainglory_api/region.rb, line 83
def find(identifier)
  new(*find_region_data(identifier)) rescue name_error(identifier)
end
Also aliased as: []
valid_short_name?(short_name) click to toggle source

Checks if short name is known

@example Checking if a short name is valid

VaingloryAPI::Region.valid_short_name?('na') # => true
VaingloryAPI::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

# 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) click to toggle source

Validates a short name

@example Validating a short name

VaingloryAPI::Region.validate_short_name!('na') # => true
VaingloryAPI::Region.validate_short_name!('QQ') # VaingloryAPI::RegionNameError

@param [String] short_name the short name of a desired region @return [True] if the short name is valid @raise [VaingloryAPI::RegionNameError] if the short name is invalid

# 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

Private Class Methods

find_region_data(identifier) click to toggle source
# File lib/vainglory_api/region.rb, line 113
def find_region_data(identifier)
  DB.detect { |data| data[1, 2].include?(identifier) }
end
name_error(identifier) click to toggle source
# File lib/vainglory_api/region.rb, line 117
def name_error(identifier)
  raise(RegionNameError, "Couldn't find region for '#{identifier}'")
end
new(type, short_name, name) click to toggle source

A new instance of Region.

@param (String) type the type of region (general, tournament, etc…) @param (String) short_name the short name of the region @param (String) name the name of the region @return [Region] a new instance of a Region @note Instantiation is private

# File lib/vainglory_api/region.rb, line 44
def initialize(type, short_name, name)
  @type = type
  @short_name = short_name
  @name = 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/vainglory_api/region.rb, line 53
def abbreviation
  @short_name
end
eql?(other) click to toggle source

Compares region to another region.

@example Compare two regions

VaingloryAPI::Region['na'].eql? VaingloryAPI::Region['na'] # => true
VaingloryAPI::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/vainglory_api/region.rb, line 64
def eql?(other)
  %i(name short_name type).all? { |a| send(a) == other.send(a) }
end