Class: SycLink::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/syclink/importer.rb

Overview

To be subclassed for link importers.

Direct Known Subclasses

Chrome, FileImporter, Firefox, InternetExplorer

Constant Summary collapse

CLEANER =

REGEX to clean tags and url names

/[^a-zA-Zäöü& ]/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_to_bookmarks, opts = {}) ⇒ Importer

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.



19
20
21
22
# File 'lib/syclink/importer.rb', line 19

def initialize(path_to_bookmarks, opts = {})
  @path = path_to_bookmarks
  @opts = opts
end

Instance Attribute Details

#optsObject

Options for importing



14
15
16
# File 'lib/syclink/importer.rb', line 14

def opts
  @opts
end

#pathObject

Path to bookmarks file



12
13
14
# File 'lib/syclink/importer.rb', line 12

def path
  @path
end

Instance Method Details

Links returned as Link objects



38
39
40
41
42
43
# File 'lib/syclink/importer.rb', line 38

def links
  rows.map do |row|
    attributes = Link::ATTRS.dup - [:url]
    Link.new(row.shift, Hash[row.map { |v| [attributes.shift, v] }])
  end
end

#readObject

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

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/syclink/importer.rb', line 27

def read
  raise NotImplementedError
end

#rowsObject

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



33
34
35
# File 'lib/syclink/importer.rb', line 33

def rows
  read
end