class OoxmlParser::Hyperlink

Class for parsing `hlinkClick`, `hyperlink` tags

Attributes

action[R]

@return [Symbol] type of action

coordinates[R]

@return [Coordinates] coordinates of link

highlight_click[R]

@return [True, False] should click be highlighted

id[R]

@return [String] id of link

runs[R]

@return [Array<ParagraphRun>] run of paragraph

tooltip[R]

@return [String] tooltip value

url[RW]

@return [OOXMLDocumentObject] url of hyperlink

Public Class Methods

new(link = nil, tooltip = nil, coordinates = nil, parent: nil) click to toggle source
Calls superclass method
# File lib/ooxml_parser/common_parser/common_data/hyperlink.rb, line 23
def initialize(link = nil,
               tooltip = nil,
               coordinates = nil,
               parent: nil)
  @url = link
  @tooltip = tooltip
  @coordinates = coordinates
  @runs = []
  super(parent: parent)
end

Public Instance Methods

parse(node) click to toggle source

Parse Hyperlink object @param node [Nokogiri::XML:Element] node to parse @return [Hyperlink] result of parsing

# File lib/ooxml_parser/common_parser/common_data/hyperlink.rb, line 42
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) unless @id.empty?
    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
    if @id && !@id.empty?
      @action = :external_link
      @url = OOXMLDocumentObject.get_link_from_rels(@id)
    end
  end
  self
end