class Pincerna::FirefoxBookmark
Show the list of Firefox bookmarks.
Constants
- ICON
The icon to show for each feedback item.
- PROFILES_SEARCH
A wildcard to searc the default profile
- QUERIES
The queries to obtain the bookmarks
Public Instance Methods
read_bookmarks()
click to toggle source
Reads the list of Firefox Bookmarks.
# File lib/pincerna/firefox_bookmark.rb, line 23 def read_bookmarks path = Dir.glob(PROFILES_SEARCH).first data = execute_command("/usr/bin/sqlite3", "-echo", "#{path}/places.sqlite", QUERIES.join("; ")) if data && !data.empty? then @folders = {} parse_bookmarks_data(data) build_paths end end
Private Instance Methods
add_folder(title, id, parent)
click to toggle source
Adds a folder to the list.
@param title [String] The name of the folder. @param id [String] The id of the folder. @param parent [String] The id of the parent folder.
# File lib/pincerna/firefox_bookmark.rb, line 78 def add_folder(title, id, parent) @folders[id.to_i] = [title, parent.to_i] if !title.empty? end
build_path(id)
click to toggle source
Builds the full path of a folder.
@param id [Fixnum] The id of the folder. @return [String] The path of the folder.
# File lib/pincerna/firefox_bookmark.rb, line 68 def build_path(id) folder = @folders[id] folder ? [folder[0]] + build_path(folder[1]).compact : [] end
build_paths()
click to toggle source
Builds the paths of the bookmarks.
# File lib/pincerna/firefox_bookmark.rb, line 57 def build_paths @bookmarks.map! do |bookmark| bookmark[:path] = " #{SEPARATOR} #{build_path(bookmark[:path].to_i).reverse.join(" #{SEPARATOR} ")}" bookmark end end
parse_bookmarks_data(data)
click to toggle source
Parses bookmarks data.
@param data [String] The data to parse.
# File lib/pincerna/firefox_bookmark.rb, line 38 def parse_bookmarks_data(data) data = StringScanner.new(data) data.skip_until(/\n/) # Discard the first line # While we're still in the first query, look for bookmarks while data.exist?(/#{QUERIES.last}/) do line = data.scan_until(/\n/).strip break if line == QUERIES.last add_bookmark(*restrict_array(line.split("|"), 3)) end # Now look for folder while !data.eos? do line = data.scan_until(/\n/).strip add_folder(*restrict_array(line.split("|"), 3)) end end
restrict_array(array, len)
click to toggle source
Restrict array making sure it does not exceed a length.
@param array [Array] The array to restrict. @param len [Fixnum] The maximum allowed length. @return [Array] The restricted array.
# File lib/pincerna/firefox_bookmark.rb, line 87 def restrict_array(array, len) array[0] = "#{array.shift}|#{array[0]}" while array.length > len array end