Class: Percept::Field
- Inherits:
-
Object
- Object
- Percept::Field
- Includes:
- ColorUtils
- Defined in:
- lib/percept/field.rb
Instance Attribute Summary collapse
-
#end_x ⇒ Object
Returns the value of attribute end_x.
-
#end_y ⇒ Object
Returns the value of attribute end_y.
-
#image ⇒ Object
Returns the value of attribute image.
-
#line ⇒ Object
Returns the value of attribute line.
-
#start_x ⇒ Object
Returns the value of attribute start_x.
-
#start_y ⇒ Object
Returns the value of attribute start_y.
Instance Method Summary collapse
- #blackish_pixels ⇒ Object
- #contains_text? ⇒ Boolean
- #enclosed_pixels ⇒ Object
- #height ⇒ Object
-
#initialize(params) ⇒ Field
constructor
A new instance of Field.
- #overlaps?(other) ⇒ Boolean
- #pixels ⇒ Object
- #store_pixels! ⇒ Object
- #width ⇒ Object
Methods included from ColorUtils
Constructor Details
#initialize(params) ⇒ Field
Returns a new instance of Field.
9 10 11 12 13 14 15 16 |
# File 'lib/percept/field.rb', line 9 def initialize(params) self.start_x = params.fetch(:start_x) self.end_x = params.fetch(:end_x) self.start_y = params.fetch(:start_y) self.end_y = params.fetch(:end_y) self.line = params.fetch(:line) self.image = params.fetch(:image) end |
Instance Attribute Details
#end_x ⇒ Object
Returns the value of attribute end_x.
7 8 9 |
# File 'lib/percept/field.rb', line 7 def end_x @end_x end |
#end_y ⇒ Object
Returns the value of attribute end_y.
7 8 9 |
# File 'lib/percept/field.rb', line 7 def end_y @end_y end |
#image ⇒ Object
Returns the value of attribute image.
7 8 9 |
# File 'lib/percept/field.rb', line 7 def image @image end |
#line ⇒ Object
Returns the value of attribute line.
7 8 9 |
# File 'lib/percept/field.rb', line 7 def line @line end |
#start_x ⇒ Object
Returns the value of attribute start_x.
7 8 9 |
# File 'lib/percept/field.rb', line 7 def start_x @start_x end |
#start_y ⇒ Object
Returns the value of attribute start_y.
7 8 9 |
# File 'lib/percept/field.rb', line 7 def start_y @start_y end |
Instance Method Details
#blackish_pixels ⇒ Object
34 35 36 |
# File 'lib/percept/field.rb', line 34 def blackish_pixels enclosed_pixels.select(&:blackish?) end |
#contains_text? ⇒ Boolean
38 39 40 |
# File 'lib/percept/field.rb', line 38 def contains_text? blackish_pixels.size > 100 end |
#enclosed_pixels ⇒ Object
30 31 32 |
# File 'lib/percept/field.rb', line 30 def enclosed_pixels image.get_pixels(start_x, start_y, width, height) end |
#height ⇒ Object
22 23 24 |
# File 'lib/percept/field.rb', line 22 def height end_y - start_y end |
#overlaps?(other) ⇒ Boolean
42 43 44 45 |
# File 'lib/percept/field.rb', line 42 def overlaps?(other) !(start_x > other.end_x || end_x < other.start_x || start_y > other.end_y || end_y < other.start_y) end |
#pixels ⇒ Object
18 19 20 |
# File 'lib/percept/field.rb', line 18 def pixels @pixels ||= top_pixels + bottom_pixels + left_pixels + right_pixels end |
#store_pixels! ⇒ Object
47 48 49 50 51 52 |
# File 'lib/percept/field.rb', line 47 def store_pixels! image.store_pixels(start_x, start_y, width, 1, top_pixels) image.store_pixels(start_x, end_y - 1, width, 1, bottom_pixels) image.store_pixels(start_x, start_y + 1, 1, height - 2, left_pixels) image.store_pixels(end_x - 1, start_y + 1, 1, height - 2, right_pixels) end |
#width ⇒ Object
26 27 28 |
# File 'lib/percept/field.rb', line 26 def width end_x - start_x end |