Class: Noty::Bookmark
- Inherits:
-
Object
- Object
- Noty::Bookmark
- Defined in:
- lib/noty/models/bookmark.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #copy ⇒ Object
- #delete ⇒ Object
- #edit ⇒ Object
-
#initialize(path) ⇒ Bookmark
constructor
A new instance of Bookmark.
- #open ⇒ Object
- #save ⇒ Object
- #to_s(short = false) ⇒ Object
Constructor Details
#initialize(path) ⇒ Bookmark
Returns a new instance of Bookmark.
10 11 12 13 14 15 16 |
# File 'lib/noty/models/bookmark.rb', line 10 def initialize(path) content = File.exist?(path) ? YAML.load_file(path) : '' @path = path @url = content['url'] @title = content['title'] end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/noty/models/bookmark.rb', line 8 def path @path end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/noty/models/bookmark.rb', line 8 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/noty/models/bookmark.rb', line 8 def url @url end |
Class Method Details
.from_url(url) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/noty/models/bookmark.rb', line 18 def self.from_url(url) file_path = File.join(STORAGE_PATH, Time.now.to_i.to_s + '.bookmark') content = begin open(url).read rescue '' end bookmark = new(file_path) bookmark.url = url bookmark.title = content.match(%r{<title>(.+)<\/title>}im).to_a[1] bookmark end |
Instance Method Details
#delete ⇒ Object
35 36 37 |
# File 'lib/noty/models/bookmark.rb', line 35 def delete File.delete path end |
#edit ⇒ Object
43 44 45 |
# File 'lib/noty/models/bookmark.rb', line 43 def edit Helpers.edit path end |
#open ⇒ Object
39 40 41 |
# File 'lib/noty/models/bookmark.rb', line 39 def open Helpers.open_url url end |
#save ⇒ Object
31 32 33 |
# File 'lib/noty/models/bookmark.rb', line 31 def save File.write(path, to_yaml) end |
#to_s(short = false) ⇒ Object
51 52 53 |
# File 'lib/noty/models/bookmark.rb', line 51 def to_s(short = false) short ? title.to_s : "#{title} (#{url})" end |