Class: Booker::Bookmark
- Inherits:
-
Data
- Object
- Data
- Booker::Bookmark
- Defined in:
- lib/booker/bookmarks.rb
Overview
one parsed bookmark. the three browsers disagree about what punctuation belongs in a title, so cleaning happens here rather than in each parser. Data.new still accepts positional args, so the parsers could pass either
Instance Attribute Summary collapse
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#display_folder ⇒ Object
the folder as a reader sees it: no leading marker, no trailing slash, a name for the top level - which "|" and "|/" both mean, both leaving nothing behind once stripped.
-
#initialize(folder:, title:, url:, id:, source: nil) ⇒ Bookmark
constructor
A new instance of Bookmark.
-
#with(**changes) ⇒ Object
ruby 3.2's Data#with copies members straight across instead of going back through #initialize, so a title replaced there would keep its punctuation and case.
Constructor Details
#initialize(folder:, title:, url:, id:, source: nil) ⇒ Bookmark
Returns a new instance of Bookmark.
146 147 148 |
# File 'lib/booker/bookmarks.rb', line 146 def initialize(folder:, title:, url:, id:, source: nil) super(folder:, title: title.gsub(/[:'"+]/, " ").downcase, url:, id:, source:) end |
Instance Attribute Details
#folder ⇒ Object (readonly)
Returns the value of attribute folder
145 146 147 |
# File 'lib/booker/bookmarks.rb', line 145 def folder @folder end |
#id ⇒ Object (readonly)
Returns the value of attribute id
145 146 147 |
# File 'lib/booker/bookmarks.rb', line 145 def id @id end |
#source ⇒ Object (readonly)
Returns the value of attribute source
145 146 147 |
# File 'lib/booker/bookmarks.rb', line 145 def source @source end |
#title ⇒ Object (readonly)
Returns the value of attribute title
145 146 147 |
# File 'lib/booker/bookmarks.rb', line 145 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url
145 146 147 |
# File 'lib/booker/bookmarks.rb', line 145 def url @url end |
Instance Method Details
#display_folder ⇒ Object
the folder as a reader sees it: no leading marker, no trailing slash, a name for the top level - which "|" and "|/" both mean, both leaving nothing behind once stripped. shared by the picker feed and the --list table, which each used to decide for itself what "top" looked like
154 155 156 157 |
# File 'lib/booker/bookmarks.rb', line 154 def display_folder stripped = folder.gsub(/^\|/, "").chomp("/") stripped.empty? ? "[root]" : stripped end |
#with(**changes) ⇒ Object
ruby 3.2's Data#with copies members straight across instead of going back through #initialize, so a title replaced there would keep its punctuation and case. 3.3 fixed it; spelling it out keeps the gemspec's ">= 3.2" true
162 |
# File 'lib/booker/bookmarks.rb', line 162 def with(**changes) = self.class.new(**to_h.merge(changes)) |