class SycLink::Website
A Website is organizing a link list. The links can be added, updated and removed. It is also possible to search for links. And finally an html representation of the Website can be created.
Attributes
links[R]
The links of the website
title[R]
The title of the website
Public Class Methods
new(title = "Link List")
click to toggle source
Create a new Website
# File lib/syclink/website.rb, line 20 def initialize(title = "Link List") @links = [] @title = title end
Public Instance Methods
add_link(link)
click to toggle source
Add a link to the website
# File lib/syclink/website.rb, line 26 def add_link(link) links << link end
find_links(search)
click to toggle source
Finds all links that contain the search string
# File lib/syclink/website.rb, line 45 def find_links(search) links.select { |link| link.contains? search } end
link_attribute_list(attribute)
click to toggle source
List all attributes of the links
# File lib/syclink/website.rb, line 57 def link_attribute_list(attribute) links.map { |link| link.send(attribute) }.uniq.sort end
links_group_by(attribute)
click to toggle source
Groups the links on the provided attribute
# File lib/syclink/website.rb, line 50 def links_group_by(attribute) links.map { |link| { key: link.send(attribute), link: link } } .group_by { |entry| entry[:key] } .each { |key, link| link.map! { |l| l[:link] }} end
list_links(args = {})
click to toggle source
List links that match the attributes
# File lib/syclink/website.rb, line 36 def list_links(args = {}) if args.empty? links else links.select { |link| link.match? args } end end
remove_link(link)
click to toggle source
Remove a link from the website
# File lib/syclink/website.rb, line 31 def remove_link(link) links.delete(link) end