Class: SC2Race

Inherits:
Object
  • Object
show all
Defined in:
lib/sc2race.rb

Constant Summary collapse

RACES =
["terran", "zerg", "protoss", "random"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(race = 'terran', path = '/images/races/') ⇒ SC2Race


Constructor method




19
20
21
22
# File 'lib/sc2race.rb', line 19

def initialize(race = 'terran', path = '/images/races/')
  @race = RACES.include?(race) ? race : 'terran'
  @path = path
end

Instance Attribute Details

#raceObject (readonly)


Accessor and constants




9
10
11
# File 'lib/sc2race.rb', line 9

def race
  @race
end

Instance Method Details

#to_sObject


Public methods




31
32
33
# File 'lib/sc2race.rb', line 31

def to_s
  "#{@race}"
end

#to_styleObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sc2race.rb', line 36

def to_style
  case @race
    when 'terran' then image_x = '-5px'; image_y = '-3px'
    when 'zerg' then image_x = '-5px'; image_y = '-60px'
    when 'protoss' then image_x = '-5px'; image_y = '-115px'
    when 'random' then image_x = '-5px'; image_y = '-168px'
    else image_x = '-5px'; image_y = '-3px'
  end
  
  "background: url('#{@path}race-symbols.png') #{image_x} #{image_y} no-repeat; width: 25px; height: 25px;"
end