Class Simpy::Link
In: lib/simpy.rb
Parent: Object

A Ruby representation of a Simpy link

Description

Use this class to construct Simpy links as a data structures in memory. This class also includes additional initialization methods that can be used to construct a Link instance from XML data emitted by the Simpy REST API or a Simpy RSS feed.

Usage

Creating a link

  link = Simpy::Link.new("The Simpy Web Site", "http://www.simpy.com", 1,
    ["tagA", "tagB"], "This is a note", "The Simpy Web Site")

Changing the values of a link

  link << {"note" => "This is a different note",
    "urlNickname" => "A different nickname",
    "tags" => link["tags"] + "tagC,tagD"}

Methods

<<   []   []=   new   parse   parse_rss   update   update!  

Attributes

values  [RW] 

Public Class methods

Create a new Link instance

Args

title:The page title associated with the link. Simpy seems to ignore this value if the page associated with the link specifies its own title.
href:The URL of the link.
tags:The tags associated with the link. At the moment, the tags value is in the form of a string array, but it might be changed in the future so that it takes a string containing comma separated values.
note:The note or message associated with the link.
urlNick:The nickname associated with the link. The nickname is displayed within the Simpy system instead of the title when a nickname is assigned.
access:The access type of the link. This value determines whether or not the link is viewable by other users. If the value is Simpy::PUBLIC, then the link is accessible to all. If the value is Simpy::PRIVATE, it is only accessible to the specific user that created it. The default value is Simpy::PUBLIC.

Usage

  Simpy::Link.new("The Simpy Web Site", "http://www.simpy.com",
    ["tagA", "tagB"], "This is a note", "The Simpy Web Site")

[Source]

     # File lib/simpy.rb, line 184
184:     def initialize title, href, tags=[], note=nil, urlNick=nil, access=PUBLIC
185:       @values = {
186:         "title" => title, "href" => href, "accessType" => access,
187:         "tags" => tags.join(","), "note" => note, "urlNickname" => urlNick}
188:     end

Create a new Link instance from an XML link item

Description

This method creates a new Link instance using values extracted from an XML link item emitted by the Simpy REST API.

Args

e:A REXML::Element instance that contains a <link> XML element.

Usage

  xmlDoc.elements.each("links/link"){|x|}.to_a.map do |e|
    Simpy::Link.parse(e)
  end

[Source]

     # File lib/simpy.rb, line 256
256:     def Link.parse e
257:       el = proc {|s| e.elements[s] ? e.elements[s].text : ""}
258:       Link.new(el["title"], el["url"]).update(
259:         "note" => el["note"], "urlNickname" => el["urlNickname"],
260:         "modDate" => el["modDate"], "addDate" => el["addDate"],
261:         "accessType" => e.attributes["accessType"], 
262:         "tags" => e.elements.to_a("tags/tag").map {|x| x.text}.join(","))
263:     end

Create a new Link instance from an RSS XML link item

Description

This method creates a new Link instance using values extracted from an RSS XML link item emitted by the Simpy RSS feed system.

Args

e:A REXML::Element instnace that contains an RSS <item> element.

Usage

  xmlDoc.elements.each("//item"){|x|}.to_a.map do |e|
    Link.parse_rss e
  end

[Source]

     # File lib/simpy.rb, line 283
283:     def Link.parse_rss e
284:       el = proc {|s| e.elements[s] ? e.elements[s].text : ""}
285:       Link.new(el["title"], el["link"]).update(
286:         "note" => el["description"], "urlNickname" => el["title"])
287:     end

Public Instance methods

<<(values)

Alias for update

Get the value of a link attribute

Description

This is a convenience method that returns the value of the specified attribute.

Args

k:The name of the attribute to return

Usage

  puts link["urlNickname"]

[Source]

     # File lib/simpy.rb, line 305
305:     def [] k
306:       @values[k]
307:     end

Set the value of a link attribute

Description

This is a convenience method that enables the user to set the value of a link attribute.

Args

k:The name of the attribute to set
v:The value to associate with the attribute

Usage

  link["urlNickname"] = "New Nickname"

[Source]

     # File lib/simpy.rb, line 328
328:     def []= k,v
329:       @values[k] = v
330:     end

Alter the value of link attributes

Description

This method allows the user to provide new values for specific link attributes. The return value is a new Link instance that includes the updated values. The original Link instance is left unaltered. The << operator is an alias of this method.

Args

values:A hash table that contains attribute names and the associated values.

Usage

  link.update("urlNickname" => "New Nickname", "note" => "This is a note")

  link << {"urlNickname" => "New Nickname", "note" => "This is a note"}

[Source]

     # File lib/simpy.rb, line 210
210:     def update values
211:       l = Link.new @values["title"], @values["href"];
212:       l.values.update @values; l.values.update values
213:       return l
214:     end

Alter the value of link attributes in place

Description

This method allows the user to update link values in place. Instead of returning a new instance that includes the altered values, it alters the values of the original instance.

Args

values:A hash table that contains attribute names and the associated values.

Usage

  link.update!("urlNickname" => "New Nickname", "note" => "This is a note")

[Source]

     # File lib/simpy.rb, line 233
233:     def update! values
234:       @values.update values
235:       self
236:     end

[Validate]