Class: OoxmlParser::ParagraphStyle

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style_name = nil, font_name = nil, font_size = nil, font_style = nil, spacing = nil, indent = nil, borders = nil, background = nil) ⇒ ParagraphStyle

Returns a new instance of ParagraphStyle.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 16

def initialize(style_name = nil, font_name = nil, font_size = nil, font_style = nil, spacing = nil,
               indent = nil, borders = nil, background = nil)
  @name = style_name if style_name
  @font_name = font_name if font_name
  @font_size = font_size if font_size
  @font_style = font_style if font_style
  @spacing = spacing if spacing
  @indent = indent if indent
  @borders = borders if borders
  @background = background if background
end

Instance Attribute Details

#backgroundObject

Returns the value of attribute background.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def background
  @background
end

#bordersObject

Returns the value of attribute borders.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def borders
  @borders
end

#font_nameObject

Returns the value of attribute font_name.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def font_name
  @font_name
end

#font_sizeObject

Returns the value of attribute font_size.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def font_size
  @font_size
end

#font_styleObject

Returns the value of attribute font_style.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def font_style
  @font_style
end

#indentObject

Returns the value of attribute indent.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def indent
  @indent
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def name
  @name
end

#spacingObject

Returns the value of attribute spacing.



7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 7

def spacing
  @spacing
end

Class Method Details

.init_by_name(style_name, object = :docx_paragraph) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 32

def self.init_by_name(style_name, object = :docx_paragraph)
  found_style = nil
  AllTestData.paragraph_settings::PARAGRAPH_STYLE_DATA.each do |style|
    found_style = style.clone if style.name == style_name
  end

  raise "Cannot find this style name - #{style_name}" if found_style.nil?

  case object
  when :table
    found_style.spacing = Spacing.new(found_style.spacing.before, 0, 1, found_style.spacing.line_rule)
  when :list
    found_style.indent = Indents.new(-0.635, 1.27, 0)
  end

  found_style
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
53
54
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 50

def ==(other)
  # FIXME, correct border comparision
  @font_name == other.font_name && @font_size.to_f == other.font_size.to_f && @font_style == other.font_style &&
    @spacing == other.spacing && @indent == other.indent && @background == other.background # && @border == other.border
end

#string_style_nameObject



28
29
30
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/paragraph_style.rb', line 28

def string_style_name
  @name.to_s.tr('_', ' ')
end