Class: SC2PortraitStyle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_index = 0, image_x = 0, image_y = 0, path = '/images/portraits/') ⇒ SC2PortraitStyle


Constructor method




18
19
20
21
22
23
# File 'lib/sc2portrait_style.rb', line 18

def initialize(image_index = 0, image_x = 0, image_y = 0, path = '/images/portraits/')
  @image_index = image_index
  @image_x = image_x
  @image_y = image_y
  @path = path
end

Instance Attribute Details

#image_indexObject (readonly)


Accessor




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

def image_index
  @image_index
end

#image_xObject (readonly)


Accessor




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

def image_x
  @image_x
end

#image_yObject (readonly)


Accessor




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

def image_y
  @image_y
end

Instance Method Details

#as_json(opts = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/sc2portrait_style.rb', line 46

def as_json(opts={})
  {
    :image_index => @image_index.to_i,
    :image_x => @image_x,
    :image_y => @image_y
  }
end

#to_sObject


Public methods




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

def to_s
  to_style
end

#to_style(size = :medium) ⇒ Object



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

def to_style(size = :medium)
  case size
    when :medium then image_x = @image_x / 2; image_y = @image_y / 2; image_size = 45
    when :big then image_x = @image_x; image_y = @image_y; image_size = 90
    else image_x = @image_x / 2; image_y = @image_y / 2; image_size = 45
  end
  
  "background: url('#{@path}#{@image_index}-#{image_size}.jpg') #{image_x}px #{image_y}px no-repeat; width: #{image_size}px; height: #{image_size}px;"
end