Class: Cat::Style::Offset

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

Instance Method Summary collapse

Constructor Details

#initialize(amount, direction) ⇒ Offset

Returns a new instance of Offset.



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

def initialize(amount, direction)
  @direction = direction
  @direction = :top unless [:top, :left, :right, :bottom].include?(@direction)

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

Instance Method Details

#to_sObject



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

def to_s
  "margin-#{@direction}: #{@amount};"
end