Class: OoxmlParser::ColorAlphaChannel

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

Overview

Class for working with AlphaChannel

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #initialize, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

This class inherits a constructor from OoxmlParser::OOXMLDocumentObject

Instance Attribute Details

#valueInteger (readonly)

Returns value of alpha channel.

Returns:

  • (Integer)

    value of alpha channel



7
8
9
# File 'lib/ooxml_parser/common_parser/common_data/colors/color_alpha_channel.rb', line 7

def value
  @value
end

Instance Method Details

#parse(node) ⇒ ColorAlphaChannel

Parse AlphaChannel value

Parameters:

  • node (Nokogiri::XML::Element)

    node to parse

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ooxml_parser/common_parser/common_data/colors/color_alpha_channel.rb', line 12

def parse(node)
  alpha_channel_node = node.xpath('a:alpha', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').first
  alpha_channel_node = node.xpath('w14:alpha', 'xmlns:w14' => 'http://schemas.microsoft.com/office/word/2010/wordml').first if alpha_channel_node.nil?

  unless alpha_channel_node
    @value = 100.0
    return self
  end

  alpha_channel_node.attributes.each do |key, value|
    case key
    when 'val'
      @value = (value.value.to_f / 1_000.0).round(0)
    end
  end

  self
end