Class: Booker::Bookmark

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

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

#folderObject (readonly)

Returns the value of attribute folder

Returns:

  • (Object)

    the current value of folder



145
146
147
# File 'lib/booker/bookmarks.rb', line 145

def folder
  @folder
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



145
146
147
# File 'lib/booker/bookmarks.rb', line 145

def id
  @id
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



145
146
147
# File 'lib/booker/bookmarks.rb', line 145

def source
  @source
end

#titleObject (readonly)

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



145
146
147
# File 'lib/booker/bookmarks.rb', line 145

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



145
146
147
# File 'lib/booker/bookmarks.rb', line 145

def url
  @url
end

Instance Method Details

#display_folderObject

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))