Class: OoxmlParser::OoxmlColor

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

Overview

Class for parsing ‘color` tag

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

#indexedFloat (readonly)

Returns Indexed id.

Returns:

  • (Float)

    Indexed id



19
20
21
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 19

def indexed
  @indexed
end

#rgbColor (readonly)

Returns rgb color.

Returns:



21
22
23
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 21

def rgb
  @rgb
end

#themeInteger (readonly)

Returns theme index.

Returns:

  • (Integer)

    theme index



13
14
15
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 13

def theme
  @theme
end

#theme_colorSymbol (readonly)

Returns theme color name.

Returns:

  • (Symbol)

    theme color name



9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 9

def theme_color
  @theme_color
end

#theme_shadeSymbol (readonly)

Returns theme shade.

Returns:

  • (Symbol)

    theme shade



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 11

def theme_shade
  @theme_shade
end

#theme_tintFloat (readonly)

Returns theme tint.

Returns:

  • (Float)

    theme tint



15
16
17
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 15

def theme_tint
  @theme_tint
end

#tintFloat (readonly)

Returns tint.

Returns:

  • (Float)

    tint



17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 17

def tint
  @tint
end

#valueColor (readonly)

Returns value of color.

Returns:

  • (Color)

    value of color



7
8
9
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 7

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



36
37
38
39
40
41
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 36

def ==(other)
  return to_color == other if other.is_a?(Color)
  return to_color == other if other.is_a?(Symbol)

  super
end

#parse(node) ⇒ OoxmlColor

Parse OoxmlColor object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 46

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'val'
      @value = Color.new.parse_hex_string(value.value.to_s)
    when 'themeColor'
      @theme_color = value.value.to_sym
    when 'themeShade'
      @theme_shade = Integer("0x#{value.value}")
    when 'theme'
      @theme = value.value.to_i
    when 'tint'
      @tint = value.value.to_f
    when 'indexed'
      @indexed = value.value.to_i
    when 'rgb'
      @rgb = Color.new.parse_hex_string(value.value)
    when 'themeTint'
      @theme_tint = value.value.hex.to_f
    end
  end
  self
end

#to_colorObject

Convert OoxmlColor to other color type

Returns:

  • (Object)

    result of conversion



25
26
27
28
29
30
31
# File 'lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb', line 25

def to_color
  return Color.get_rgb_by_color_index(indexed) if indexed
  return ThemeColors.new(parent: self).parse_color_theme(theme, tint) if theme
  return rgb if rgb

  value
end