class SycLink::Importer

To be subclassed for link importers.

To be subclassed for link importers.

Constants

CLEANER

REGEX to clean tags and url names

Attributes

opts[RW]

Options for importing

path[RW]

Path to bookmarks file

Public Class Methods

new(path_to_bookmarks, opts = {}) click to toggle source

Creates a new Importer and sets the path to the bookmarks file. Opts may be :level which indicates to which levels tags should be imported and :tags to set tags during import.

# File lib/syclink/importer.rb, line 19
def initialize(path_to_bookmarks, opts = {})
  @path = path_to_bookmarks
  @opts = opts
end

Public Instance Methods

read() click to toggle source

To be overridden! Read the raw data from the bookmarks file. The bookmarks file has to be provided during initialization with initialize

# File lib/syclink/importer.rb, line 27
def read
  raise NotImplementedError
end
rows() click to toggle source

Links values returned in an Array. Default implementation returns values from read.

# File lib/syclink/importer.rb, line 33
def rows
  read
end

Protected Instance Methods

extract_tags(tag_string) click to toggle source

Extracts the tags from a tag string. If a level is provided during initialization the level is restricting the count of tags imported based on the level value. If tags are provided these are added to the end of the tag_string. If a level is provided these tags are considered first

# File lib/syclink/importer.rb, line 51
def extract_tags(tag_string)
  opts[:tags].gsub!(',', '/') if opts[:tags]
  tags = (tag_string << opts[:tags]).compact
                                    .join('/')
                                    .gsub(/[^a-zA-Zäöü&#\/, ]/, " ")
                                    .squeeze(" ")
                                    .split('/')

  if tags.empty? || opts[:level] == 0
    "Default"
  else
    level = [opts[:level] || tags.size, tags.size].min
    tags[-level..-1].join(',')
  end

end
url_name(name_source) click to toggle source

Create a name from the url if no name is given.

# File lib/syclink/importer.rb, line 69
def url_name(name_source)
  name_source.gsub(CLEANER, " ").squeeze(" ")
end