Class: VaingloryAPI::Region

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, short_name, name) ⇒ Region

Note:

Instantiation is private

A new instance of Region.

Parameters:

  • type (String)

    the type of region (general, tournament, etc…)

  • short_name (String)

    the short name of the region

  • name (String)

    the name of the 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

#nameString (readonly)

Returns the name of the region.

Returns:

  • (String)

    the name of the region



29
30
31
# File 'lib/vainglory_api/region.rb', line 29

def name
  @name
end

#short_nameString (readonly)

Returns the short name of the region.

Returns:

  • (String)

    the short name of the region



32
33
34
# File 'lib/vainglory_api/region.rb', line 32

def short_name
  @short_name
end

#typeString (readonly)

Returns the type of region.

Returns:

  • (String)

    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”)

Examples:

Finding a region

VaingloryAPI::Region.find('eu')

Finding a region (alternative syntax)

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

Parameters:

  • identifier (String)

    the target name or abbreviation of the region

Returns:

  • (Region)

    if the identifier is found

Raises:

See Also:



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

Examples:

Checking if a short name is valid

VaingloryAPI::Region.valid_short_name?('na') # => true
VaingloryAPI::Region.valid_short_name?('QQ') # => false

Parameters:

  • short_name (String)

    the short name of a desired region

Returns:

  • (Boolean)

    whether the 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

Examples:

Validating a short name

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

Parameters:

  • short_name (String)

    the short name of a desired region

Returns:

  • (True)

    if the short name is valid

Raises:



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

#abbreviationString

Alias method for short name

Returns:

  • (String)

    the “short name” of the region



53
54
55
# File 'lib/vainglory_api/region.rb', line 53

def abbreviation
  @short_name
end

#eql?(other) ⇒ Boolean

Compares region to another region.

Examples:

Compare two regions

VaingloryAPI::Region['na'].eql? VaingloryAPI::Region['na'] # => true
VaingloryAPI::Region['na'].eql? VaingloryAPI::Region['sg'] # => false

Parameters:

  • other (VaingloryAPU::Region)

    another region to compare for quality

Returns:

  • (Boolean)

    whether all attributes match



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