Class: Cat::Style::Stroke

Inherits:
Object
  • Object
show all
Defined in:
lib/cat/style/stroke.rb

Instance Method Summary collapse

Constructor Details

#initialize(width, color = nil, only = [:top, :right, :bottom, :left]) ⇒ Stroke

Returns a new instance of Stroke.



4
5
6
7
8
9
10
11
# File 'lib/cat/style/stroke.rb', line 4

def initialize(width, color = nil, only = [:top, :right, :bottom, :left])
  @width = width || '3'
  @color = color || 'black'
  @only = only

  @width = "#{@width}px" if @width.is_a?(Integer)
  @width = '3px' unless (@width =~ /px|%|em|rem$/) > 0
end

Instance Method Details

#to_sObject



13
14
15
# File 'lib/cat/style/stroke.rb', line 13

def to_s
  @only.map { |direction| "border-#{direction}: #{@width} solid #{@color};" }.join("\n")
end