Class: EPUB::Searcher::Result
- Inherits:
-
Object
- Object
- EPUB::Searcher::Result
- Defined in:
- lib/epub/searcher/result.rb
Defined Under Namespace
Classes: Step
Instance Attribute Summary collapse
-
#end_steps ⇒ Object
readonly
Returns the value of attribute end_steps.
-
#parent_steps ⇒ Object
readonly
Returns the value of attribute parent_steps.
-
#start_steps ⇒ Object
readonly
Returns the value of attribute start_steps.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(parent_steps, start_steps, end_steps) ⇒ Result
constructor
A new instance of Result.
- #to_cfi_s ⇒ Object
- #to_xpath_and_offset(with_xmlns = false) ⇒ Object
Constructor Details
#initialize(parent_steps, start_steps, end_steps) ⇒ Result
Returns a new instance of Result.
40 41 42 |
# File 'lib/epub/searcher/result.rb', line 40 def initialize(parent_steps, start_steps, end_steps) @parent_steps, @start_steps, @end_steps = parent_steps, start_steps, end_steps end |
Instance Attribute Details
#end_steps ⇒ Object (readonly)
Returns the value of attribute end_steps.
35 36 37 |
# File 'lib/epub/searcher/result.rb', line 35 def end_steps @end_steps end |
#parent_steps ⇒ Object (readonly)
Returns the value of attribute parent_steps.
35 36 37 |
# File 'lib/epub/searcher/result.rb', line 35 def parent_steps @parent_steps end |
#start_steps ⇒ Object (readonly)
Returns the value of attribute start_steps.
35 36 37 |
# File 'lib/epub/searcher/result.rb', line 35 def start_steps @start_steps end |
Class Method Details
.aggregate_step_intersection(steps1, steps2) ⇒ Array<Array<Array>>
Returns Thee arrays:
-
“intersection” of
steps1
andsteps2
. “intersection” here is not the term of mathmatics -
remaining steps of
steps1
-
remaining steps of
steps2
.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/epub/searcher/result.rb', line 16 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 |
Instance Method Details
#==(other) ⇒ Object
65 66 67 68 |
# File 'lib/epub/searcher/result.rb', line 65 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_s ⇒ Object
59 60 61 62 63 |
# File 'lib/epub/searcher/result.rb', line 59 def to_cfi_s [@parent_steps, @start_steps, @end_steps].collect {|steps| steps ? steps.collect(&:to_cfi_s).join : nil }.compact.join(',') end |
#to_xpath_and_offset(with_xmlns = false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/epub/searcher/result.rb', line 44 def to_xpath_and_offset(with_xmlns=false) xpath = (@parent_steps + @start_steps).reduce('.') {|path, step| case step.type when :element path + '/%s*[%d]' % [with_xmlns ? 'xhtml:' : nil, step.index + 1] when :text path + '/text()[%s]' % [step.index + 1] else path end } [xpath, @start_steps.last.index] end |