Class: SC2League
- Inherits:
-
Object
- Object
- SC2League
- Defined in:
- lib/sc2league.rb
Constant Summary collapse
- LEAGUES =
["no league", "bronze", "silver", "gold", "platinum", "diamond", "master", "grandmaster"]
Instance Attribute Summary collapse
-
#league_name ⇒ Object
readonly
————————————————————————–.
-
#league_type ⇒ Object
readonly
————————————————————————–.
-
#rank ⇒ Object
readonly
————————————————————————–.
Instance Method Summary collapse
- #as_json(opts = {}) ⇒ Object
-
#initialize(league_name = 'bronze', league_type = '1v1', rank = 0, path = '/images/leagues/') ⇒ SC2League
constructor
————————————————————————–.
-
#to_s ⇒ Object
————————————————————————–.
- #to_style(size = :medium) ⇒ Object
Constructor Details
#initialize(league_name = 'bronze', league_type = '1v1', rank = 0, path = '/images/leagues/') ⇒ SC2League
Constructor method
19 20 21 22 23 24 |
# File 'lib/sc2league.rb', line 19 def initialize(league_name = 'bronze', league_type = '1v1', rank = 0, path = '/images/leagues/') @league_name = LEAGUES.include?(league_name) ? league_name : 'bronze' @league_type = league_type @rank = rank @path = path end |
Instance Attribute Details
#league_name ⇒ Object (readonly)
Accessor and constants
9 10 11 |
# File 'lib/sc2league.rb', line 9 def league_name @league_name end |
#league_type ⇒ Object (readonly)
Accessor and constants
9 10 11 |
# File 'lib/sc2league.rb', line 9 def league_type @league_type end |
#rank ⇒ Object (readonly)
Accessor and constants
9 10 11 |
# File 'lib/sc2league.rb', line 9 def rank @rank end |
Instance Method Details
#as_json(opts = {}) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/sc2league.rb', line 56 def as_json(opts={}) { :league_name => @league_name, :league_type => @league_type, :rank => @rank, } end |
#to_s ⇒ Object
Public methods
33 34 35 |
# File 'lib/sc2league.rb', line 33 def to_s "#{@league_name} #{@league_type} rank #{@rank}" end |
#to_style(size = :medium) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sc2league.rb', line 37 def to_style(size = :medium) case size when :small then image_x = '-145px'; image_size = '28px' when :medium then image_x = '-100px'; image_size = '45px' when :big then image_x = '0px'; image_size = '100px' else image_x = '-100px'; image_size = '45px' end case @rank when 1..8 then image_y = '-150px' when 9..25 then image_y = '-100px' when 26..50 then image_y = '-50px' when 51..200 then image_y = '0px' else image_y = '0px' end "background: url('#{@path}#{@league_name.gsub(/\s/, '')}.png') #{image_x} #{image_y} no-repeat; width: #{image_size}; height: #{image_size};" end |