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.
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
The links of the website
The title of the website
Public Class Methods
Create a new Website
# File lib/syclink/website.rb, line 22 def initialize(title = "Link List") @links = [] @title = title end
Public Instance Methods
Add a link to the website
# File lib/syclink/website.rb, line 28 def add_link(link) links << link end
Finds all links that contain the search string
# File lib/syclink/website.rb, line 53 def find_links(search) links.select { |link| link.contains? search } end
List all attributes of the links
# File lib/syclink/website.rb, line 106 def link_attribute_list(attribute, separator = nil) links.map {|link| link.send(attribute).split(separator)}.flatten.uniq.sort end
Create multiple Links based on the attribute provided. The specified spearator will splitt the attribute value in distinct values and for each different value a Link will be created
# File lib/syclink/website.rb, line 92 def links_duplicate_on(attribute, separator) links.map do |link| link.send(attribute).split(separator).collect do |value| link.dup.update(Hash[attribute, value]) end end.flatten end
Groups the links on the provided attribute. If no links array is provided the links from self are used
# File lib/syclink/website.rb, line 76 def links_group_by(attribute, linkz = links) linkz.map { |link| { key: link.send(attribute), link: link } } .group_by { |entry| entry[:key] } .each { |key, link| link.map! { |l| l[:link] }} end
Groups the links on the provided attribute. If the attribute's value contains the provided separator, the value is split up and each of the values is used as group key
# File lib/syclink/website.rb, line 85 def links_group_by_separated(attribute, separator) links_group_by(attribute, links_duplicate_on(attribute, separator)) end
List links that match the attributes
# File lib/syclink/website.rb, line 38 def list_links(args = {}) if args.empty? links else links.select { |link| link.match? args } end end
Merge links based on the provided attribue to one link by combining the values. The first link will be updated and the obsolete links are deleted and will be returned
# File lib/syclink/website.rb, line 60 def merge_links_on(attribute, concat_string = ',') links_group_by(attribute) .select { |key, link_list| links.size > 1 } .map do |key, link_list| merge_attributes = Link::ATTRS - [attribute] link_list.first .update(Hash[extract_columns(link_list, merge_attributes) .map { |c| c.uniq.join(concat_string) } .collect { |v| [merge_attributes.shift, v] }]) link_list.shift link_list.each { |link| links.delete(link) } end end
Remove a link from the website
# File lib/syclink/website.rb, line 33 def remove_link(link) links.delete(link) end
Check availability of links. Returns the links' url with code '200' if reachable other wise with code 'Error'.
# File lib/syclink/website.rb, line 48 def report_links_availability links.map { |link| [link.url, link.response] } end
Return an array of all link values as rows
# File lib/syclink/website.rb, line 101 def rows links.map { |link| link.row } end