Class: Bookmarkeron::Merger
- Inherits:
-
Object
- Object
- Bookmarkeron::Merger
- Defined in:
- lib/bookmarkeron/merger.rb
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #bookmarks_from_source ⇒ Object
- #bookmarks_from_target ⇒ Object
-
#initialize(opts = {}) ⇒ Merger
constructor
A new instance of Merger.
- #result ⇒ Object
- #result_json ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Merger
Returns a new instance of Merger.
10 11 12 13 |
# File 'lib/bookmarkeron/merger.rb', line 10 def initialize(opts = {}) @target = opts[:target] || CHROME_BOOKMARKS_PATH @source = opts[:source] end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/bookmarkeron/merger.rb', line 8 def target @target end |
Instance Method Details
#bookmarks_from_source ⇒ Object
15 16 17 18 |
# File 'lib/bookmarkeron/merger.rb', line 15 def bookmarks_from_source yaml = YAML.load_file @source yaml["bookmarks"] end |
#bookmarks_from_target ⇒ Object
40 41 42 |
# File 'lib/bookmarkeron/merger.rb', line 40 def bookmarks_from_target @target_json ||= JSON.parse(File.read(@target)) end |
#result ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bookmarkeron/merger.rb', line 20 def result bookmarks = bookmarks_from_target["roots"]["bookmark_bar"]["children"] bookmark_next_id = bookmarks_from_source.size bookmarks_from_source.each do |bookmark| next if bookmarks.find {|existing| existing["url"] == bookmark["url"]} bookmarks << bookmark.merge({ "type"=> "url", "date" => "13010285566708500", "id" => bookmark_next_id }) bookmark_next_id = bookmark_next_id + 1 end bookmarks_from_target end |
#result_json ⇒ Object
36 37 38 |
# File 'lib/bookmarkeron/merger.rb', line 36 def result_json JSON.pretty_generate result end |