Class: Goldendocx::Documents::Properties::PageMarginProperty

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/goldendocx/documents/properties/page_margin_property.rb

Instance Method Summary collapse

Methods included from Element

#build_element, #initialize, #namespace, #tag, #tag_name, #to_element, #to_xml

Methods included from HasChildren

#children, #read_child, #read_children

Methods included from HasAttributes

#assign_attributes, #attributes, #read_attributes

Instance Method Details

#margin=(*args) ⇒ Object

Follow html margin style setting



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/goldendocx/documents/properties/page_margin_property.rb', line 21

def margin=(*args)
  args = Array(*args)
  raise StandardError("wrong number of arguments (given #{args.length}, expected 1..4)") unless (1..4).cover?(args.length)

  margins =
    case args.length
    when 1 then [args.first] * 4
    when 2 then [args.first, args.last, args.first, args.last]
    when 3 then [args.first, args.second, args.last, args.second]
    else args
    end
  assign_attributes(**%i[top right bottom left].zip(margins).to_h)
end