Class: Squib::Margin

Inherits:
Object
  • Object
show all
Defined in:
lib/squib/commands/data/template_option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = expand_shorthand(
      definition.split(/\s+/).map!(&:to_f))
  elsif definition.is_a? Numeric
    @top, @right, @bottom, @left = expand_shorthand [definition]
  elsif definition.instance_of? Array
    @top, @right, @bottom, @left = expand_shorthand definition
  else
    raise ArgumentError, 'Invalid value, must be either string or array'
  end
end

Instance Attribute Details

#bottomObject (readonly)


5
6
7
# File 'lib/squib/commands/data/template_option.rb', line 5

def bottom
  @bottom
end

#leftObject (readonly)


6
7
8
# File 'lib/squib/commands/data/template_option.rb', line 6

def left
  @left
end

#rightObject (readonly)


4
5
6
# File 'lib/squib/commands/data/template_option.rb', line 4

def right
  @right
end

#topObject (readonly)


3
4
5
# File 'lib/squib/commands/data/template_option.rb', line 3

def top
  @top
end