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

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(link = nil, tooltip = nil, coordinates = nil, parent: nil) ⇒ Hyperlink

Returns a new instance of Hyperlink.



10
11
12
13
14
15
16
17
18
19
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 10

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

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 4

def action
  @action
end

Returns the value of attribute action_link.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 5

def action_link
  @action_link
end

#coordinatesObject

Returns the value of attribute coordinates.



4
5
6
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 4

def coordinates
  @coordinates
end

#highlight_clickObject

Returns the value of attribute highlight_click.



4
5
6
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 4

def highlight_click
  @highlight_click
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#runsArray<ParagraphRun> (readonly)

Returns run of paragraph.

Returns:



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

def runs
  @runs
end

#tooltipObject

Returns the value of attribute tooltip.



4
5
6
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 4

def tooltip
  @tooltip
end

#urlObject Also known as: link, link_to

Returns the value of attribute url.



4
5
6
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 4

def url
  @url
end

Instance Method Details

#parse(node) ⇒ Hyperlink

Parse Hyperlink object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
# File 'lib/ooxml_parser/common_parser/common_data/hyperlink.rb', line 29

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'location'
      @url = Coordinates.parse_coordinates_from_string(value.value)
    when 'id'
      @id = value.value
      @url = OOXMLDocumentObject.get_link_from_rels(@id)
    when 'tooltip'
      @tooltip = value.value
    when 'ref'
      @coordinates = Coordinates.parse_coordinates_from_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
    @url = OOXMLDocumentObject.get_link_from_rels(@id).scan(/\d+/).join('').to_i
  else
    unless @id.nil?
      @action = :external_link
      @url = OOXMLDocumentObject.get_link_from_rels(@id)
    end
  end
  self
end