class EPUB::Searcher::Result

Attributes

end_steps[R]
parent_steps[R]
start_steps[R]

Public Class Methods

aggregate_step_intersection(steps1, steps2) click to toggle source

@example

Result.aggregate_step_intersection([a, b, c], [a, b, d]) # => [[a, b], [c], [d]]

@example

Result.aggregate_step_intersection([a, b, c], [a, d, c]) # => [[a], [b, c], [d, c]]
# Note that c here is not included in the first element of returned value.

@param steps1 [Array<Step>, Array<Array>] @param steps2 [Array<Step>, Array<Array>] @return [Array<Array<Array>>] Three arrays:

1. "intersection" of +steps1+ and +steps2+. "intersection" here is not the term of mathmatics
2. remaining steps of +steps1+
3. remaining steps of +steps2+
# File lib/epub/searcher/result.rb, line 18
def aggregate_step_intersection(steps1, steps2)
  intersection = []
  steps1_remaining = []
  steps2_remaining = []
  broken = false
  steps1.zip steps2 do |step1, step2|
    broken = true unless step1 && step2 && step1 == step2
    if broken
      steps1_remaining << step1 unless step1.nil?
      steps2_remaining << step2 unless step2.nil?
    else
      intersection << step1
    end
  end

  [intersection, steps1_remaining, steps2_remaining]
end
new(parent_steps, start_steps, end_steps) click to toggle source

@param parent_steps [Array<Step>] common steps between start and end @param start_steps [Array<Step>] steps to start from parent_steps @param end_steps [Array<Step>] steps to end from parent_steps

# File lib/epub/searcher/result.rb, line 42
def initialize(parent_steps, start_steps, end_steps)
  @parent_steps, @start_steps, @end_steps = parent_steps, start_steps, end_steps
end

Public Instance Methods

==(other) click to toggle source
# File lib/epub/searcher/result.rb, line 53
def ==(other)
  [@parent_steps + @start_steps.to_a] == [other.parent_steps + other.start_steps.to_a] and
    [@parent_steps + @end_steps.to_a] == [other.parent_steps + other.end_steps.to_a]
end
to_cfi() click to toggle source
# File lib/epub/searcher/result.rb, line 46
def to_cfi
  str = [@parent_steps, @start_steps, @end_steps].collect {|steps|
    steps ? steps.collect(&:to_cfi).join : nil
  }.compact.join(',')
  EPUB::CFI(str)
end