Module: BitmapCompiler::Core::BitmapActions

Included in:
BitmapController
Defined in:
lib/bitmap_compiler/core/bitmap_actions.rb

Instance Method Summary collapse

Instance Method Details

#change_color(row:, column:, color: Bitmap::STANDARD_COLOR) ⇒ Object



5
6
7
8
9
10
11
12
13
# 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
    return_output(message: InvalidPixelError.new.message)
  end
end

#change_horizontal_line(column:, start_row:, end_row:, color: Bitmap::STANDARD_COLOR) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# 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
    return_output(message: InvalidCoordinatesError.new.message)
  end
end

#change_vertical_line(row:, start_column:, end_column:, color: Bitmap::STANDARD_COLOR) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bitmap_compiler/core/bitmap_actions.rb', line 54

def change_vertical_line(row:, start_column:, end_column:, color: Bitmap::STANDARD_COLOR)
  return 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
    return_output(message: InvalidCoordinatesError.new.message)
  end
end

#clearObject



15
16
17
18
19
20
21
22
23
# File 'lib/bitmap_compiler/core/bitmap_actions.rb', line 15

def clear
  return image_not_found unless bitmap

  if bitmap.clear
    return_output
  else
    return_output(message: ImageNotClearedError.new.message)
  end
end

#create_bitmap(args) ⇒ Object



25
26
27
28
29
30
31
32
# 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
    return_output(message: InvalidDimensionsError.new.message)
  end
end


34
35
36
37
38
# 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_commandObject



68
69
70
# File 'lib/bitmap_compiler/core/bitmap_actions.rb', line 68

def unknown_command
  return_output(message: UnknownCommandError.new.message)
end