class SycLink::Link

Creates a link with url, name, description and tag

Creates a link with url, name, description and tag

Constants

ATTRS

Attributes that are accessible

Public Class Methods

new(url, params = {}) click to toggle source

Create a new link with url and params. If params are not provided defaults are used for name the url is used, description is empty and tag is set to 'untagged'

Usage

Link.new("http://example.com", name: "example",
                               description: "For testing purposes",
                               tag:         "Test,Example")

Params

url

the URL of the link

name

the name of the link. If not given the URL is used

description

the description of the link (optional)

tag

if not given it is set to 'untagged'

# File lib/syclink/link.rb, line 34
def initialize(url, params = {})
  @url         = url
  params       = defaults(url).merge(select_defined(params))
  @name        = params[:name]
  @description = params[:description]
  @tag         = params[:tag]
end

Public Instance Methods

contains?(search) click to toggle source

Checks whether the search string is contained in one or more of the attributes. If the search string is found true is returned otherwise false

link.contains?("example.com")
# File lib/syclink/link.rb, line 65
def contains?(search)
  search = search.delete(' ').downcase
  target = instance_variables.map { |v| instance_variable_get v }.join
  target.downcase.delete(' ').scan(search).size > 0
end
match?(args) click to toggle source

Checks whether the link matches the values provided by args and returns true if so otherwise false

link.match?(name: "Example", tag: "Test")
# File lib/syclink/link.rb, line 55
def match?(args)
  select_defined(args).reduce(true) do |sum, attribute|
    sum = sum && (send(attribute[0]) == attribute[1])
  end 
end
row() click to toggle source

Return the values of the link in an array

link.row
# File lib/syclink/link.rb, line 73
def row
  [ url, name, description, tag ]
end
update(args) click to toggle source

Updates the attributes of the link specified by args and returns the updated link

link.update(name: "Example website for testing purposes")
# File lib/syclink/link.rb, line 45
def update(args)
  select_defined(args).each do |attribute, value|
    send("#{attribute}=", value)
  end
  self
end