Class: Percept::LineFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/percept/line_filter.rb

Instance Method Summary collapse

Instance Method Details

#blackish_bottom_pixels(line) ⇒ Object



17
18
19
# File 'lib/percept/line_filter.rb', line 17

def blackish_bottom_pixels(line)
  bottom_pixels(line).select(&:blackish?)
end

#bottom_corners?(line) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/percept/line_filter.rb', line 81

def bottom_corners?(line)
  left_bottom_corner?(line) && right_bottom_corner?(line)
end

#bottom_left_blackish?(line) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/percept/line_filter.rb', line 45

def bottom_left_blackish?(line)
  bottom_left_columns(line).any? { |column| column.all?(&:blackish?) }
end

#bottom_left_columns(line) ⇒ Object



57
58
59
# File 'lib/percept/line_filter.rb', line 57

def bottom_left_columns(line)
  line.columns_for(line.start_x..(line.start_x + 5), line.end_y)
end

#bottom_pixels(line) ⇒ Object



21
22
23
# File 'lib/percept/line_filter.rb', line 21

def bottom_pixels(line)
  line.columns_for(line.start_x..line.end_x, line.end_y + 1).flatten
end

#bottom_right_blackish?(line) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/percept/line_filter.rb', line 53

def bottom_right_blackish?(line)
  bottom_right_columns(line).any? { |column| column.all?(&:blackish?) }
end

#bottom_right_columns(line) ⇒ Object



65
66
67
# File 'lib/percept/line_filter.rb', line 65

def bottom_right_columns(line)
  line.columns_for((line.end_x - 5)..line.end_x, line.end_y)
end

#divided?(line) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/percept/line_filter.rb', line 85

def divided?(line)
  line.split.length > 1
end

#filter_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/percept/line_filter.rb', line 5

def filter_line?(line)
  table_top?(line) || top_of_letters?(line) || too_thick?(line)
end

#left_bottom_corner?(line) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/percept/line_filter.rb', line 33

def left_bottom_corner?(line)
  top_left_blackish?(line) && !bottom_left_blackish?(line)
end

#left_top_corner?(line) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/percept/line_filter.rb', line 25

def left_top_corner?(line)
  bottom_left_blackish?(line) && !top_left_blackish?(line)
end

#right_bottom_corner?(line) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/percept/line_filter.rb', line 37

def right_bottom_corner?(line)
  top_right_blackish?(line) && !bottom_right_blackish?(line)
end

#right_top_corner?(line) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/percept/line_filter.rb', line 29

def right_top_corner?(line)
  bottom_right_blackish?(line) && !top_right_blackish?(line)
end

#table_border?(line) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/percept/line_filter.rb', line 89

def table_border?(line)
  table_top?(line) || table_bottom?(line)
end

#table_bottom?(line) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/percept/line_filter.rb', line 77

def table_bottom?(line)
  bottom_corners?(line) && !divided?(line)
end

#table_top?(line) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/percept/line_filter.rb', line 73

def table_top?(line)
  left_top_corner?(line) && right_top_corner?(line)
end

#too_thick?(line) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/percept/line_filter.rb', line 9

def too_thick?(line)
  line.height > Percept.config.max_line_height
end

#top_left_blackish?(line) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/percept/line_filter.rb', line 41

def top_left_blackish?(line)
  top_left_columns(line).any? { |column| column.all?(&:blackish?) }
end

#top_left_columns(line) ⇒ Object



61
62
63
# File 'lib/percept/line_filter.rb', line 61

def top_left_columns(line)
  line.columns_for(line.start_x..(line.start_x + 5), line.start_y - 2)
end

#top_of_letters?(line) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/percept/line_filter.rb', line 13

def top_of_letters?(line)
  blackish_bottom_pixels(line).length.to_f / line.length > 0.20
end

#top_right_blackish?(line) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/percept/line_filter.rb', line 49

def top_right_blackish?(line)
  top_right_columns(line).any? { |column| column.all?(&:blackish?) }
end

#top_right_columns(line) ⇒ Object



69
70
71
# File 'lib/percept/line_filter.rb', line 69

def top_right_columns(line)
  line.columns_for((line.end_x - 5)..line.end_x, line.start_y - 2)
end