Class: Rubyword::Writer::Style::Paragraph
- Defined in:
- lib/rubyword/writer/style/paragraph.rb
Constant Summary collapse
- ParagraphStyleList =
{ text_align: 'w:jc', spacing: 'w:spacing', indent_left: 'w:ind', indent_right: 'w:ind', indent_between: 'w:ind' }.freeze
Instance Attribute Summary
Attributes inherited from Base
#rubyword, #section, #style, #xml
Instance Method Summary collapse
-
#write(style) ⇒ Object
write paragraph style.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Rubyword::Writer::Style::Base
Instance Method Details
#write(style) ⇒ Object
write paragraph style
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubyword/writer/style/paragraph.rb', line 16 def write(style) return unless !style.nil? && style.is_a?(Hash) @xml.send('w:pPr') { style.keys.each do |style_name| style_name = style_name.to_sym next unless ParagraphStyleList.keys.include?(style_name) value = style[style_name] attribute = case style_name.to_s when 'spacing' {'w:after' => value} when 'indent_left' {'w:left' => value} when 'indent_right' {'w:right' => value} when 'indent_between' v = value.split '-' next unless v.is_a?(Array) { 'w:left' => v[0].to_i, 'w:right' => v[1].to_i } when !!value == value nil else {'w:val' => value} end doc_style = ParagraphStyleList[style_name] @xml.send(doc_style, attribute) end } end |