Class: Squib::Margin
- Inherits:
-
Object
- Object
- Squib::Margin
- Defined in:
- lib/squib/commands/data/template_option.rb
Instance Attribute Summary collapse
- #bottom ⇒ Object readonly
- #left ⇒ Object readonly
- #right ⇒ Object readonly
- #top ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(definition) ⇒ Margin
constructor
Create a new margin definition.
Constructor Details
#initialize(definition) ⇒ Margin
Create a new margin definition.
Takes definition
which can either be a space-separated String
or an Array
of Float
and will translate it to the top, right, bottom and left members.
The syntax follows how CSS parses margin shorthand strings.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/squib/commands/data/template_option.rb', line 16 def initialize(definition) if definition.instance_of? String @top, @right, @bottom, @left = ( definition.split(/\s+/).map!(&:to_f)) elsif definition.is_a? Numeric @top, @right, @bottom, @left = [definition] elsif definition.instance_of? Array @top, @right, @bottom, @left = definition else raise ArgumentError, 'Invalid value, must be either string or array' end end |
Instance Attribute Details
#bottom ⇒ Object (readonly)
5 6 7 |
# File 'lib/squib/commands/data/template_option.rb', line 5 def bottom @bottom end |
#left ⇒ Object (readonly)
6 7 8 |
# File 'lib/squib/commands/data/template_option.rb', line 6 def left @left end |
#right ⇒ Object (readonly)
4 5 6 |
# File 'lib/squib/commands/data/template_option.rb', line 4 def right @right end |
#top ⇒ Object (readonly)
3 4 5 |
# File 'lib/squib/commands/data/template_option.rb', line 3 def top @top end |