module BitmapCompiler::Core::BitmapActions
BitmapActions
shares role behavior
Public Instance Methods
change_color(row:, column:, color: Bitmap::STANDARD_COLOR)
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 5 def change_color(row:, column:, color: Bitmap::STANDARD_COLOR) return image_not_found unless bitmap if bitmap.change_pixel(row, column, color) return_output else raise BitmapCompiler::Core::Errors::InvalidPixelError end end
change_horizontal_line(column:, start_row:, end_row:, color: Bitmap::STANDARD_COLOR)
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 40 def change_horizontal_line(column:, start_row:, end_row:, color: Bitmap::STANDARD_COLOR) return image_not_found unless bitmap if bitmap.valid_horizontal_line_coordinates?(column, start_row, end_row) (start_row..end_row).each do |row_index| bitmap.change_pixel(row_index, column, color) end return_output else raise Errors::InvalidCoordinatesError end end
change_vertical_line(row:, start_column:, end_column:, color: Bitmap::STANDARD_COLOR)
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 54 def change_vertical_line(row:, start_column:, end_column:, color: Bitmap::STANDARD_COLOR) image_not_found unless bitmap if bitmap.valid_vertical_line_coordinates?(row, start_column, end_column) (start_column..end_column).each do |column_index| bitmap.change_pixel(row, column_index, color) end return_output else raise BitmapCompiler::Core::Errors::InvalidCoordinatesError end end
clear()
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 15 def clear return image_not_found unless bitmap if bitmap.clear return_output else raise BitmapCompiler::Core::Errors::ImageNotClearedError end end
create_bitmap(args)
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 25 def create_bitmap(args) if args[:width].between?(Bitmap::MIN_WIDTH, Bitmap::MAX_WIDTH) && args[:height].between?(Bitmap::MIN_HEIGHT, Bitmap::MAX_HEIGHT) return_output(bitmap: Bitmap.new(args[:width], args[:height])) else raise BitmapCompiler::Core::Errors::InvalidDimensionsError end end
print()
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 34 def print return image_not_found unless bitmap return_output(message: bitmap.print) end
unknown_command()
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 68 def unknown_command raise BitmapCompiler::Core::Errors::UnknownCommandError end
Private Instance Methods
image_not_found()
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 74 def image_not_found raise BitmapCompiler::Core::Errors::NoImageFoundError end
return_output(args = {})
click to toggle source
# File lib/bitmap_compiler/core/bitmap_actions.rb, line 78 def return_output(args = {}) Output.new(bitmap: args[:bitmap], message: args[:message]) end