Module: GetUrl::LocalUrls
Overview
The LocalUrls manages the local stored urls.
Instance Attribute Summary collapse
-
#private_source_id ⇒ Object
readonly
Returns the value of attribute private_source_id.
Instance Method Summary collapse
-
#delete_url(url) ⇒ Object
Deletes the given url from the local storage.
-
#load_urls ⇒ Object
Loads all urls items from the local storage.
-
#save_url(url, name, options = {}) ⇒ Object
Adds or updates the data for the given url, and stores in the local storage.
-
#save_urls ⇒ Object
Stores all urls ites to the local storage.
Instance Attribute Details
#private_source_id ⇒ Object (readonly)
Returns the value of attribute private_source_id.
11 12 13 |
# File 'lib/geturl/geturl-local-urls.rb', line 11 def private_source_id @private_source_id end |
Instance Method Details
#delete_url(url) ⇒ Object
Deletes the given url from the local storage.
51 52 53 54 55 |
# File 'lib/geturl/geturl-local-urls.rb', line 51 def delete_url(url) load_urls if @urls.nil? @items.delete_if {|item| item['url'] == url} save_urls end |
#load_urls ⇒ Object
Loads all urls items from the local storage.
14 15 16 |
# File 'lib/geturl/geturl-local-urls.rb', line 14 def load_urls @items = FileManager.load_items_from_yaml_file(@local_urls_file) rescue [] end |
#save_url(url, name, options = {}) ⇒ Object
Adds or updates the data for the given url, and stores in the local storage.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/geturl/geturl-local-urls.rb', line 30 def save_url(url, name, = {}) return if (url.to_s.empty?) || (name.to_s.empty?) load_urls @items.delete_if {|item| item['url'] == url} ['tags'] ||= [] ['tags'].map! {|tag| tag.strip} @items << { 'url' => url, 'source' => 'local', 'name' => name, 'description' => ['description'], 'tags' => ['tags'] } save_urls end |
#save_urls ⇒ Object
Stores all urls ites to the local storage.
19 20 21 22 23 |
# File 'lib/geturl/geturl-local-urls.rb', line 19 def save_urls FileManager.save_items_to_yaml_file(@items, @local_urls_file) FileManager.clear_all_items_cache return @items.size end |