Class: Parchment::ODT::Style

Inherits:
Style
  • Object
show all
Defined in:
lib/parchment/formats/odt/style.rb

Constant Summary collapse

ALIGNMENT_CONVERSION =

Because the OpenOffice standard uses ‘start’, ‘end’, etc.

{
  start: :left,
  end: :right,
  center: :center
}
TEXT_PROPERTIES =
[
  'font-size',
  'font-weight',
  'font-style',
  'text-underline-style'
]

Constants inherited from Style

Style::AVAILABLE_FORMATTING

Instance Attribute Summary

Attributes inherited from Style

#family, #font_size, #font_style, #font_weight, #id, #name, #parent_style_name, #text_align, #text_underline_style

Instance Method Summary collapse

Methods inherited from Style

#aligned_center?, #aligned_left?, #aligned_right?, #bold?, #italic?, #paragraph?, #text?, #underline?

Constructor Details

#initialize(node) ⇒ Style

Returns a new instance of Style.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/parchment/formats/odt/style.rb', line 21

def initialize(node)
  @node = node
  @node.attributes.map { |k, v| [k, v.value] }.each do |prop|
    prop_name = prop[0].gsub('-', '_')
    instance_variable_set("@#{prop_name}", prop[1])
  end
  instance_variable_set("@id", @name)
  @node.children.each do |style_child|
    case style_child.name
    when 'paragraph-properties'
      if style_child.attributes['text-align']
        @text_align = ALIGNMENT_CONVERSION[style_child.attributes['text-align'].value.to_sym]
      end
    when 'text-properties'
      TEXT_PROPERTIES.each do |prop|
        style_attr = style_child.attributes[prop]
        if style_attr
          value = style_attr.value
          value = value.to_i if prop == 'font-size'
          instance_variable_set("@#{prop.gsub('-', '_')}", value)
        end
      end
    end
  end
end