Class: Spreadsheet::Link

Inherits:
String
  • Object
show all
Includes:
Encodings
Defined in:
lib/spreadsheet/link.rb

Overview

The Link class. Is a Subclass of String, which lets you treat a Cell that contains a Link just as if it was a String (containing the link’s description if there is one or the url with fragment otherwise), but gives you access to the url, fragment and target_frame if you need it.

Interesting Attributes

#url

The Uniform Resource Location this Link points to.

#fragment

Also called text mark: example.com/page.html#fragment

#target_frame

Which frame a Link should be opened in, should also support the special frames _blank, _parent, _self and _top.

#dos

Excel may store a DOS-Filename together with the long Filename introduced in VFAT. You probably will not need this, but if you do, here is where you can find it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = '', description = url, fragment = nil) ⇒ Link

Returns a new instance of Link.



23
24
25
26
27
# File 'lib/spreadsheet/link.rb', line 23

def initialize url='', description=url, fragment=nil
  super description
  @url = url
  @fragment = fragment
end

Instance Attribute Details

#dosObject

Returns the value of attribute dos.



22
23
24
# File 'lib/spreadsheet/link.rb', line 22

def dos
  @dos
end

#fragmentObject

Returns the value of attribute fragment.



22
23
24
# File 'lib/spreadsheet/link.rb', line 22

def fragment
  @fragment
end

#target_frameObject

Returns the value of attribute target_frame.



22
23
24
# File 'lib/spreadsheet/link.rb', line 22

def target_frame
  @target_frame
end

#urlObject

Returns the value of attribute url.



22
23
24
# File 'lib/spreadsheet/link.rb', line 22

def url
  @url
end

Instance Method Details

#hrefObject

The Url with the fragment appended if present.



30
31
32
33
34
35
36
# File 'lib/spreadsheet/link.rb', line 30

def href
  href = (@url || @dos).to_s.dup
  if @fragment
    href << client('#', 'UTF-8') << @fragment
  end
  href
end

#to_uriObject

Attempts to parse the output of href. May raise a URI::InvalidURIError



39
40
41
# File 'lib/spreadsheet/link.rb', line 39

def to_uri
  URI.parse href
end