Class: Deskbot::Bitmap
- Inherits:
-
Object
- Object
- Deskbot::Bitmap
- Defined in:
- lib/deskbot/bitmap.rb
Constant Summary collapse
Instance Method Summary collapse
- #all(image_path, tolerance: nil) ⇒ Object
- #all_color(color, tolerance: nil) ⇒ Object
- #bounds ⇒ Object
-
#color_at(x, y) ⇒ Object
rubocop:disable Naming/MethodParameterName.
- #count(image_path, tolerance: nil) ⇒ Object
- #eql?(image_path, tolerance: nil) ⇒ Boolean
- #find(image_path, tolerance: nil) ⇒ Object
- #find_color(color, tolerance: nil) ⇒ Object
-
#initialize(provider) ⇒ Bitmap
constructor
A new instance of Bitmap.
- #save(image_path) ⇒ Object
Constructor Details
#initialize(provider) ⇒ Bitmap
Returns a new instance of Bitmap.
16 17 18 |
# File 'lib/deskbot/bitmap.rb', line 16 def initialize(provider) @provider = provider end |
Instance Method Details
#all(image_path, tolerance: nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/deskbot/bitmap.rb', line 66 def all(image_path, tolerance: nil) @provider.all( Types::String[image_path], Types::Float.optional[tolerance] ) .map { |point| Point.new(point) } end |
#all_color(color, tolerance: nil) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/deskbot/bitmap.rb', line 74 def all_color(color, tolerance: nil) @provider.all_color( Rgba[color], Types::Float.optional[tolerance] ) .map { |point| Point.new(point) } end |
#bounds ⇒ Object
24 25 26 |
# File 'lib/deskbot/bitmap.rb', line 24 def bounds Area.new(@provider.bounds) end |
#color_at(x, y) ⇒ Object
rubocop:disable Naming/MethodParameterName
28 29 30 31 |
# File 'lib/deskbot/bitmap.rb', line 28 def color_at(x, y) # rubocop:disable Naming/MethodParameterName red, green, blue, alpha = @provider.color_at(x, y) Color.new(red:, green:, blue:, alpha:) end |
#count(image_path, tolerance: nil) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/deskbot/bitmap.rb', line 82 def count(image_path, tolerance: nil) @provider.count( Types::String[image_path], Types::Float.optional[tolerance] ) end |
#eql?(image_path, tolerance: nil) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/deskbot/bitmap.rb', line 33 def eql?(image_path, tolerance: nil) @provider.bitmap_eq( Types::String[image_path], Types::Float.optional[tolerance] ) end |
#find(image_path, tolerance: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/deskbot/bitmap.rb', line 40 def find(image_path, tolerance: nil) result = @provider.find( Types::String[image_path], Types::Float.optional[tolerance] ) if result Success(Point.new(result)) else Failure(:not_found) end end |
#find_color(color, tolerance: nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/deskbot/bitmap.rb', line 53 def find_color(color, tolerance: nil) found = @provider.find_color( Rgba[color], Types::Float.optional[tolerance] ) if found Success(Point.new(found)) else Failure(:not_found) end end |
#save(image_path) ⇒ Object
20 21 22 |
# File 'lib/deskbot/bitmap.rb', line 20 def save(image_path) @provider.save(Types::String[image_path]) end |