Class: Fyodor::Entry
- Inherits:
-
Object
- Object
- Fyodor::Entry
- Defined in:
- lib/fyodor/entry.rb
Constant Summary collapse
- TYPE =
{ note: "note", highlight: "highlight", bookmark: "bookmark", clip: "clip" }
- ATTRS =
[ :book_title, :book_author, :text, :desc, :type, :loc, :loc_start, :page, :page_start, :time ]
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Override this method for sorting.
-
#==(other) ⇒ Object
(also: #eql?)
Override the following methods for deduplication.
- #desc_parsed? ⇒ Boolean
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(args) ⇒ Entry
constructor
A new instance of Entry.
Constructor Details
#initialize(args) ⇒ Entry
Returns a new instance of Entry.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fyodor/entry.rb', line 25 def initialize(args) ATTRS.each do |attr| instance_variable_set("@#{attr}", args[attr]) end # These are our comparables. Let's make sure they are numbers. @loc_start = @loc_start.to_i @page_start = @page_start.to_i raise ArgumentError, "Invalid Entry type" unless TYPE.value?(@type) || @type.nil? end |
Instance Method Details
#<=>(other) ⇒ Object
Override this method for sorting.
50 51 52 53 54 |
# File 'lib/fyodor/entry.rb', line 50 def <=>(other) return (@page_start <=> other.page_start) if @loc_start == 0 @loc_start <=> other.loc_start end |
#==(other) ⇒ Object Also known as: eql?
Override the following methods for deduplication.
57 58 59 60 61 62 63 |
# File 'lib/fyodor/entry.rb', line 57 def ==(other) return false if (@type != other.type || @text != other.text) return (@loc == other.loc && @page == other.page) if desc_parsed? && other.desc_parsed? @desc == other.desc end |
#desc_parsed? ⇒ Boolean
45 46 47 |
# File 'lib/fyodor/entry.rb', line 45 def desc_parsed? ! @type.nil? && (@loc_start != 0 || @page_start != 0) end |
#empty? ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/fyodor/entry.rb', line 37 def empty? if @type == TYPE[:bookmark] || @type.nil? @desc.strip == "" else @text.strip == "" end end |
#hash ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/fyodor/entry.rb', line 67 def hash if desc_parsed? @text.hash ^ @type.hash ^ @loc.hash ^ @page.hash else @text.hash ^ @desc.hash end end |