module GetUrl::LocalUrls
The LocalUrls
manages the local stored urls.
Attributes
private_source_id[R]
Public Instance Methods
delete_url(url)
click to toggle source
Deletes the given url from the local storage.
@param [String] url The url.
# 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()
click to toggle source
Loads all urls items from the local storage.
# 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 = {})
click to toggle source
Adds or updates the data for the given url, and stores in the local storage.
@param [String] url The url. @param [String] name The name. @param [Hash] options The options, which might contains the tags and description.
# File lib/geturl/geturl-local-urls.rb, line 30 def save_url(url, name, options = {}) return if (url.to_s.empty?) || (name.to_s.empty?) load_urls @items.delete_if {|item| item['url'] == url} options['tags'] ||= [] options['tags'].map! {|tag| tag.strip} @items << { 'url' => url, 'source' => 'local', 'name' => name, 'description' => options['description'], 'tags' => options['tags'] } save_urls end
save_urls()
click to toggle source
Stores all urls ites to the local storage.
# 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