Class: HalcyonAPI::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/halcyon_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(identifier) ⇒ Region

A new instance of Region.

Parameters:

  • identifier (String)

    the name or short name of a region

Raises:

See Also:



44
45
46
47
48
49
50
51
# 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

Instance Attribute Details

#nameString (readonly)

Returns the name of the region.

Returns:

  • (String)

    the name of the region



29
30
31
# File 'lib/halcyon_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/halcyon_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/halcyon_api/region.rb', line 35

def type
  @type
end

Class Method Details

.detect_region_info(identifier) ⇒ Array?

Detects region data from DB constant

Examples:

Detecting region data from DB

HalcyonAPI::Region.detech_region_info('na')

Parameters:

  • identifier (String)

    the name or short name of the desired region

Returns:

  • (Array)

    if region data is found

  • (nil)

    if region data is not found

See Also:



96
97
98
# File 'lib/halcyon_api/region.rb', line 96

def detect_region_info(identifier)
  DB.detect { |region_data| region_data[1, 2].include?(identifier) }
end

.valid_short_name?(short_name) ⇒ Boolean

Checks if short name is known

Examples:

Checking if a short name is valid

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

See Also:



84
85
86
# File 'lib/halcyon_api/region.rb', line 84

def valid_short_name?(short_name)
  SHORT_NAMES.include?(short_name)
end

Instance Method Details

#abbreviationString

Alias method for short name

Returns:

  • (String)

    the “short name” of the region



56
57
58
# File 'lib/halcyon_api/region.rb', line 56

def abbreviation
  @short_name
end

#eql?(other) ⇒ Boolean

Compares region to another region.

Examples:

Compare two regions

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

Parameters:

  • other (VaingloryAPU::Region)

    another region to compare for quality

Returns:

  • (Boolean)

    whether all attributes match



67
68
69
# File 'lib/halcyon_api/region.rb', line 67

def eql?(other)
  %i(name short_name type).all? { |a| send(a) == other.send(a) }
end