Method: PDF::Reader::Turtletext#fuzzed_y
- Defined in:
- lib/pdf/reader/turtletext.rb
#fuzzed_y(input) ⇒ Object
Returns an Array with fuzzed positioning, ordered by decreasing y position. Row content order by x position.
[ fuzzed_y_position, [[x_position,content]] ]
Given input as a hash:
{ y_position: { x_position: content}}
Fuzz factors: y_precision
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pdf/reader/turtletext.rb', line 51 def fuzzed_y(input) output = [] input.keys.sort.reverse.each do |precise_y| matching_y = output.map(&:first).select{|new_y| (new_y - precise_y).abs < y_precision }.first || precise_y y_index = output.index{|y| y.first == matching_y } new_row_content = input[precise_y].to_a if y_index row_content = output[y_index].last row_content += new_row_content output[y_index] = [matching_y,row_content.sort{|a,b| a.first <=> b.first }] else output << [matching_y,new_row_content.sort{|a,b| a.first <=> b.first }] end end output end |