Class: OoxmlParser::Hyperlink

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

Overview

Class for parsing ‘hlinkClick`, `hyperlink` 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(link = nil, tooltip = nil, coordinates = nil, parent: nil) ⇒ Hyperlink

Returns a new instance of Hyperlink.



25
26
27
28
29
30
31
32
33
34
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 25

def initialize(link = nil,
               tooltip = nil,
               coordinates = nil,
               parent: nil)
  @url = link
  @tooltip = tooltip
  @coordinates = coordinates
  @runs = []
  super(parent: parent)
end

Instance Attribute Details

#actionSymbol (readonly)

Returns type of action.

Returns:

  • (Symbol)

    type of action



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

def action
  @action
end

Returns value of action link.

Returns:

  • (String)

    value of action link



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

def action_link
  @action_link
end

#anchorString (readonly)

Returns anchor value.

Returns:

  • (String)

    anchor value



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

def anchor
  @anchor
end

#coordinatesCoordinates (readonly)

Returns coordinates of link.

Returns:



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

def coordinates
  @coordinates
end

#highlight_clickTrue, False (readonly)

Returns should click be highlighted.

Returns:

  • (True, False)

    should click be highlighted



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

def highlight_click
  @highlight_click
end

#idString (readonly)

Returns id of link.

Returns:

  • (String)

    id of link



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

def id
  @id
end

#runsArray<ParagraphRun> (readonly)

Returns run of paragraph.

Returns:



23
24
25
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 23

def runs
  @runs
end

#tooltipString (readonly)

Returns tooltip value.

Returns:

  • (String)

    tooltip value



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

def tooltip
  @tooltip
end

#urlOOXMLDocumentObject Also known as: link, link_to

Returns url of hyperlink.

Returns:



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

def url
  @url
end

Instance Method Details

#parse(node) ⇒ Hyperlink

Parse Hyperlink object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 44

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'anchor'
      @anchor = value.value
    when 'location'
      @url = Coordinates.new.parse_string(value.value)
    when 'id'
      @id = value.value
      @url = root_object.get_link_from_rels(@id) unless @id.empty?
    when 'tooltip'
      @tooltip = value.value
    when 'ref'
      @coordinates = Coordinates.new.parse_string(value.value)
    when 'action'
      @action_link = value.value
    when 'highlightClick'
      @highlight_click = attribute_enabled?(value)
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'r'
      @runs << ParagraphRun.new(parent: self).parse(node_child)
    end
  end

  case @action_link
  when 'ppaction://hlinkshowjump?jump=previousslide'
    @action = :previous_slide
  when 'ppaction://hlinkshowjump?jump=nextslide'
    @action = :next_slide
  when 'ppaction://hlinkshowjump?jump=firstslide'
    @action = :first_slide
  when 'ppaction://hlinkshowjump?jump=lastslide'
    @action = :last_slide
  when 'ppaction://hlinksldjump'
    @action = :slide
    parse_url_for_slide_link
  else
    if meaningful_id?
      @action = :external_link
      @url = root_object.get_link_from_rels(@id)
    end
  end
  self
end