class Fyodor::Entry

Constants

ATTRS
TYPE

Public Class Methods

new(args) click to toggle source
# 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

Public Instance Methods

<=>(other) click to toggle source

Override this method for sorting.

# 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) click to toggle source

Override the following methods for deduplication.

# 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
Also aliased as: eql?
desc_parsed?() click to toggle source
# File lib/fyodor/entry.rb, line 45
def desc_parsed?
  ! @type.nil? && (@loc_start != 0 || @page_start != 0)
end
empty?() click to toggle source
# File lib/fyodor/entry.rb, line 37
def empty?
  if @type == TYPE[:bookmark] || @type.nil?
    @desc.strip == ""
  else
    @text.strip == ""
  end
end
eql?(other)
Alias for: ==
hash() click to toggle source
# 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