class EPUB::CFI::Location

{Location} indicates a point in an EPUB Publication.

Attributes

paths[R]

Public Class Methods

from_parent_and_subpath(parent_path, subpath) click to toggle source
# File lib/epub/cfi.rb, line 39
def from_parent_and_subpath(parent_path, subpath)
  new(resolve_path(parent_path, subpath))
end
new(paths=[]) click to toggle source
# File lib/epub/cfi.rb, line 59
def initialize(paths=[])
  @paths = paths
end

Private Class Methods

resolve_path(parent_path, subpath) click to toggle source
# File lib/epub/cfi.rb, line 45
def resolve_path(parent_path, subpath)
  paths = parent_path.collect(&:dup)
  return paths unless subpath

  subpath = subpath.collect(&:dup)
  offset = subpath.last.offset
  paths.last.steps.concat subpath.shift.steps
  paths.concat subpath
  paths.last.instance_variable_set :@offset, offset

  paths
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/epub/cfi.rb, line 67
def <=>(other)
  index = 0
  other_paths = other.paths
  cmp = nil
  paths.each do |path|
    other_path = other_paths[index]
    return 1 unless other_path
    cmp = path <=> other_path
    break unless cmp == 0
    index += 1
  end

  unless cmp == 0
    if cmp == 1 and paths[index].offset and other_paths[index + 1]
      return nil
    else
      return cmp
    end
  end

  return nil if paths.last.offset && other_paths[index]

  return -1 if other_paths[index]

  0
end
initialize_copy(original) click to toggle source
# File lib/epub/cfi.rb, line 63
def initialize_copy(original)
  @paths = original.paths.collect(&:dup)
end
inspect() click to toggle source
# File lib/epub/cfi.rb, line 102
def inspect
  "#<#{self.class}:#{path_string}>"
end
join(*other_paths) click to toggle source
# File lib/epub/cfi.rb, line 106
def join(*other_paths)
  new_paths = paths.dup
  other_paths.each do |path|
    new_paths << path
  end
  self.class.new(new_paths)
end
path_string() click to toggle source
# File lib/epub/cfi.rb, line 94
def path_string
  paths.join('!')
end
to_s() click to toggle source
# File lib/epub/cfi.rb, line 98
def to_s
 "epubcfi(#{path_string})"
end