lib/syclink/designer.rb in syclink-0.0.2 vs lib/syclink/designer.rb in syclink-0.1.0

- old
+ new

@@ -27,17 +27,35 @@ # Reads arguments from a CSV file and creates links accordingly. The links # are added to the websie def add_links_from_file(file) File.foreach(file) do |line| - url, name, description, tag = line.split(';') + next if line.chomp.empty? + url, name, description, tag = line.chomp.split(';') website.add_link(Link.new(url, { name: name, description: description, tag: tag })) end end + # Accepts and SycLink::Importer to import Links and add them to the website + def import_links(importer) + importer.links.each do |link| + website.add_link(link) + end + end + + # Export links to specified format + def export(format) + message = "to_#{format.downcase}" + if website.respond_to? message + website.send(message) + else + raise "cannot export to #{format}" + end + end + # List links contained in the website and optionally filter on attributes def list_links(args = {}) website.list_links(args) end @@ -48,9 +66,24 @@ # Updates a link. The link is identified by the URL. If there is more than # one link with the same URL, only the first link is updated def update_link(url, args) website.find_links(url).first.update(args) + end + + def update_links_from_file(file) + File.foreach(file) do |line| + next if line.chomp.empty? + url, name, description, tag = line.chomp.split(';') + website.find_links(url).first.update({ name: name, + description: description, + tag: tag }) + end + end + + # Merge links with same URL + def merge_links + website.merge_links_on(:url) end # Deletes one or more links from the website. Returns the deleted links. # Expects the links provided in an array def remove_links(urls)