Class: OoxmlParser::Shade

Inherits:
OOXMLDocumentObject show all
Extended by:
Gem::Deprecate
Defined in:
lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb

Overview

Class for parsing ‘w:shd` object

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(value: nil, color: nil, fill: nil, parent: nil) ⇒ Shade

Returns a new instance of Shade.



13
14
15
16
17
18
19
20
21
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb', line 13

def initialize(value: nil,
               color: nil,
               fill: nil,
               parent: nil)
  @value = value
  @color = color
  @fill = fill
  super(parent: parent)
end

Instance Attribute Details

#colorSymbol

Returns color of shade.

Returns:

  • (Symbol)

    color of shade



9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb', line 9

def color
  @color
end

#fillColor

Returns fill of shade.

Returns:

  • (Color)

    fill of shade



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb', line 11

def fill
  @fill
end

#valueSymbol

Returns value of shade.

Returns:

  • (Symbol)

    value of shade



7
8
9
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb', line 7

def value
  @value
end

Instance Method Details

#parse(node) ⇒ Shade

Parse Shade

Parameters:

  • node (Nokogiri::XML:Node)

    with Shade

Returns:

  • (Shade)

    result of parsing



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb', line 33

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'val'
      @value = value.value.to_sym
    when 'color'
      @color = value.value.to_sym
    when 'fill'
      @fill = Color.new(parent: self).parse_hex_string(value.value.to_s)
    end
  end
  self
end

#to_background_colorOoxmlParser::Color

Helper method to get background color

Returns:



49
50
51
52
53
54
55
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb', line 49

def to_background_color
  return nil unless fill

  background_color = fill
  background_color.set_style(value) if value
  background_color
end

#to_sString

Returns text representation.

Returns:

  • (String)

    text representation



24
25
26
27
28
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb', line 24

def to_s
  "Value: `#{value}`, " \
    "Color: `#{color}`, " \
    "Fill: `#{fill}`"
end