Class: OoxmlParser::Underline

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/underline.rb

Overview

Class for parsing ‘u` tags

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(style = :none, color = nil, parent: nil) ⇒ Underline

Returns a new instance of Underline.



12
13
14
15
16
# File 'lib/ooxml_parser/common_parser/common_data/underline.rb', line 12

def initialize(style = :none, color = nil, parent: nil)
  @style = style == 'single' ? :single : style
  @color = color
  super(parent: parent)
end

Instance Attribute Details

#colorColor

Returns color of underline.

Returns:

  • (Color)

    color of underline



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/underline.rb', line 8

def color
  @color
end

#styleObject

Returns the value of attribute style.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/underline.rb', line 6

def style
  @style
end

#valueSymbol (readonly)

Returns value of underline.

Returns:

  • (Symbol)

    value of underline



10
11
12
# File 'lib/ooxml_parser/common_parser/common_data/underline.rb', line 10

def value
  @value
end

Instance Method Details

#==(other) ⇒ True, False

Compare this object to other

Parameters:

  • other (Object)

    any other object

Returns:

  • (True, False)

    result of comparision



21
22
23
24
25
26
27
28
29
30
# File 'lib/ooxml_parser/common_parser/common_data/underline.rb', line 21

def ==(other)
  case other
  when Underline
    @style.to_sym == other.style.to_sym && @color == other.color
  when Symbol
    @style.to_sym == other
  else
    false
  end
end

#parse(node) ⇒ Underline

Parse Underline object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ooxml_parser/common_parser/common_data/underline.rb', line 44

def parse(node)
  parse_attributes(node) if node.is_a?(Nokogiri::XML::Element)

  case node
  when 'sng'
    @style = :single
  when 'none'
    @style = :none
  end
  self
end

#to_sString

Returns result of convert of object to string.

Returns:

  • (String)

    result of convert of object to string



33
34
35
36
37
38
39
# File 'lib/ooxml_parser/common_parser/common_data/underline.rb', line 33

def to_s
  if @color.nil?
    @style.to_s
  else
    "#{@style} #{@color}"
  end
end