class VaingloryAPI::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
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
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
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
# File lib/vainglory_api/region.rb, line 113 def find_region_data(identifier) DB.detect { |data| data[1, 2].include?(identifier) } end
# File lib/vainglory_api/region.rb, line 117 def name_error(identifier) raise(RegionNameError, "Couldn't find region for '#{identifier}'") end
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
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
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