module BookmarksReader
TODO: make private methods… well, private!
Constants
- MOZILLA_FIREFOX_CONF_DIR
Attributes
db[R]
Public Instance Methods
bookmarks_count()
click to toggle source
# File lib/fundler/bookmarks_reader.rb, line 45 def bookmarks_count stored_bookmarks.size end
drop_bookmarks(format = :txt)
click to toggle source
drop_bookmarks
browse the home directory of the current user, locate the places.sqlite
db_file generated by Firefox and retrieve all the bookmarks stored.
# File lib/fundler/bookmarks_reader.rb, line 88 def drop_bookmarks(format = :txt) output = [] if db get_bookmarks_with_url_title_descr_tag.each_with_index do |row, index| case format.intern when :txt output << "#{index}: #{row}" output << '---' when :html puts "TODO" when :markdown puts "TODO" when :json output << row.to_json else # exit 1 end end end File.open("./bookmarks_dump.#{format.to_s}", 'w') do |file| file.puts output end end
dump_places()
click to toggle source
# File lib/fundler/bookmarks_reader.rb, line 128 def dump_places FileUtils.cp(locate_places, pwd) end
find_bookmarks_by_tag(tag_id)
click to toggle source
# File lib/fundler/bookmarks_reader.rb, line 17 def find_bookmarks_by_tag(tag_id) query = QUERY_BY_TAG query.gsub(/@tag_id/,tag_id) db.execute(query) do |row| (result ||= []) << row end end
get_bookmarks_with_url_title_descr_tag()
click to toggle source
# File lib/fundler/bookmarks_reader.rb, line 75 def get_bookmarks_with_url_title_descr_tag unless stored_bookmarks.empty? db.execute(BOOKMARKS_QUERY).each do |bookmark| url, title, id, description = bookmark @stored_bookmarks[id].merge!({url: url, description: description}) end end @stored_bookmarks end
get_tag_by_id(id)
click to toggle source
# File lib/fundler/bookmarks_reader.rb, line 34 def get_tag_by_id(id) query = QUERY_FOR_TAG_BY_ID query.gsub(/@tag_id/,id) db.get_first_row(query) end
locate_places()
click to toggle source
# File lib/fundler/bookmarks_reader.rb, line 112 def locate_places begin dot_firefox = Dir.open(MOZILLA_FIREFOX_CONF_DIR) profile_dir = dot_firefox.select {|dir| dir =~ /.*default/} db_file = MOZILLA_FIREFOX_CONF_DIR + profile_dir.join + '/places.sqlite' rescue Errno::ENOENT puts "no db_bookmarks found" # exit 1 nil end end
stored_bookmarks()
click to toggle source
# File lib/fundler/bookmarks_reader.rb, line 40 def stored_bookmarks # humm... I don't like this choice @stored_bookmarks ||= get_bookmarks_with_tags end