Sha256: 5835268571979a1c2b1f595956c61fcc295b4f7462d4a068b7bd20f435e912b4

Contents?: true

Size: 580 Bytes

Versions: 1

Compression:

Stored size: 580 Bytes

Contents

require 'bitmapped/commands/base_command'

module Bitmapped
  module Commands
    class InvertCommand < BaseCommand

      ALPHABET = [*'A'..'Z']

      def command_id
        "N"
      end

      def process_command(bitmap, input)
        Validators::ValidateBitmapInitialised.parse_and_validate(bitmap)
        bitmap.pixels.each_with_index do |row, index|
          bitmap.pixels[index] = row.collect{ |color| invert_color(color) }
        end
      end

      private
        def invert_color(color)
          ALPHABET[-(ALPHABET.index(color)+1)]
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitmapped-0.2.0 lib/bitmapped/commands/invert_command.rb