Class: SC2PortraitStyle
- Inherits:
-
Object
- Object
- SC2PortraitStyle
- Defined in:
- lib/sc2portrait_style.rb
Instance Attribute Summary collapse
-
#image_index ⇒ Object
readonly
————————————————————————–.
-
#image_x ⇒ Object
readonly
————————————————————————–.
-
#image_y ⇒ Object
readonly
————————————————————————–.
Instance Method Summary collapse
- #as_json(opts = {}) ⇒ Object
-
#initialize(image_index = 0, image_x = 0, image_y = 0, path = '/images/portraits/') ⇒ SC2PortraitStyle
constructor
————————————————————————–.
-
#to_s ⇒ Object
————————————————————————–.
- #to_style(size = :medium) ⇒ Object
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_index ⇒ Object (readonly)
Accessor
9 10 11 |
# File 'lib/sc2portrait_style.rb', line 9 def image_index @image_index end |
#image_x ⇒ Object (readonly)
Accessor
9 10 11 |
# File 'lib/sc2portrait_style.rb', line 9 def image_x @image_x end |
#image_y ⇒ Object (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_s ⇒ Object
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 |