Class: SycLink::Website
- Inherits:
-
Object
- Object
- SycLink::Website
- Includes:
- Exporter
- Defined in:
- lib/syclink/website.rb
Overview
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.
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
The links of the website.
-
#title ⇒ Object
readonly
The title of the website.
Instance Method Summary collapse
-
#add_link(link) ⇒ Object
Add a link to the website.
-
#find_links(search) ⇒ Object
Finds all links that contain the search string.
-
#initialize(title = "Link List") ⇒ Website
constructor
Create a new Website.
-
#link_attribute_list(attribute) ⇒ Object
List all attributes of the links.
-
#links_group_by(attribute) ⇒ Object
Groups the links on the provided attribute.
-
#list_links(args = {}) ⇒ Object
List links that match the attributes.
-
#remove_link(link) ⇒ Object
Remove a link from the website.
Methods included from Exporter
Constructor Details
#initialize(title = "Link List") ⇒ Website
Create a new Website
20 21 22 23 |
# File 'lib/syclink/website.rb', line 20 def initialize(title = "Link List") @links = [] @title = title end |
Instance Attribute Details
#links ⇒ Object (readonly)
The links of the website
15 16 17 |
# File 'lib/syclink/website.rb', line 15 def links @links end |
#title ⇒ Object (readonly)
The title of the website
17 18 19 |
# File 'lib/syclink/website.rb', line 17 def title @title end |
Instance Method Details
#add_link(link) ⇒ Object
Add a link to the website
26 27 28 |
# File 'lib/syclink/website.rb', line 26 def add_link(link) links << link end |
#find_links(search) ⇒ Object
Finds all links that contain the search string
45 46 47 |
# File 'lib/syclink/website.rb', line 45 def find_links(search) links.select { |link| link.contains? search } end |
#link_attribute_list(attribute) ⇒ Object
List all attributes of the links
57 58 59 |
# 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) ⇒ Object
Groups the links on the provided attribute
50 51 52 53 54 |
# 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 = {}) ⇒ Object
List links that match the attributes
36 37 38 39 40 41 42 |
# 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) ⇒ Object
Remove a link from the website
31 32 33 |
# File 'lib/syclink/website.rb', line 31 def remove_link(link) links.delete(link) end |