Class: Cat::Style::Position
- Inherits:
-
Object
- Object
- Cat::Style::Position
- Defined in:
- lib/cat/style/position.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(top: nil, right: nil, bottom: nil, left: nil) ⇒ Position
constructor
A new instance of Position.
- #to_s ⇒ Object
- #validate(value) ⇒ Object
Constructor Details
#initialize(top: nil, right: nil, bottom: nil, left: nil) ⇒ Position
Returns a new instance of Position.
4 5 6 7 8 9 |
# File 'lib/cat/style/position.rb', line 4 def initialize(top: nil, right: nil, bottom: nil, left: nil) @top = validate(top) @right = validate(right) @bottom = validate(bottom) @left = validate(left) end |
Instance Method Details
#to_s ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/cat/style/position.rb', line 18 def to_s %{ position: absolute; #{@top ? "top: #{@top};" : ""} #{@right ? "right: #{@right};" : ""} #{@bottom ? "bottom: #{@bottom};" : ""} #{@left ? "left: #{@left};" : ""} } end |
#validate(value) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/cat/style/position.rb', line 11 def validate(value) return nil if value.nil? return "#{value}px" if value.is_a?(Integer) return "0px" unless (value =~ /px|%|em|rem$/) > 0 value end |