class EPUB::CFI::Path

Attributes

offset[R]
steps[R]

Public Class Methods

new(steps=[], offset=nil) click to toggle source
# File lib/epub/cfi.rb, line 118
def initialize(steps=[], offset=nil)
  @steps, @offset = steps, offset
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/epub/cfi.rb, line 131
def <=>(other)
  other_steps = other.steps
  index = 0
  steps.each do |step|
    other_step = other_steps[index]
    return 1 unless other_step
    cmp = step <=> other_step
    return cmp unless cmp == 0
    index += 1
  end

  return -1 if other_steps[index]

  other_offset = other.offset
  if offset
    if other_offset
      offset <=> other_offset
    else
      1
    end
  else
    if other_offset
      -1
    else
      0
    end
  end
end
initialize_copy(original) click to toggle source
# File lib/epub/cfi.rb, line 122
def initialize_copy(original)
  @steps = original.steps.collect(&:dup)
  @offset = original.offset.dup if original.offset
end
to_s() click to toggle source
# File lib/epub/cfi.rb, line 127
def to_s
  @string_cache ||= (steps.join + offset.to_s)
end