Class: BitmapCompiler::Core::Editor

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmap_compiler/core/editor.rb

Overview

Responsibility: process the files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bitmap: nil) ⇒ Editor

Returns a new instance of Editor.



9
10
11
# File 'lib/bitmap_compiler/core/editor.rb', line 9

def initialize(bitmap: nil)
  @bitmap = bitmap
end

Instance Attribute Details

#bitmapObject (readonly)

Returns the value of attribute bitmap.



7
8
9
# File 'lib/bitmap_compiler/core/editor.rb', line 7

def bitmap
  @bitmap
end

Instance Method Details

#process_line(input) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/bitmap_compiler/core/editor.rb', line 19

def process_line(input)
  output = execute(input)

  @bitmap = output.bitmap if output.bitmap

  output.print
end

#run(file) ⇒ Object



13
14
15
16
17
# File 'lib/bitmap_compiler/core/editor.rb', line 13

def run(file)
  raise BitmapCompiler::Core::Errors::IncorrectFileError if file.nil? || !File.exist?(file)

  File.open(file).each { |line| process_line(line.chomp) }
end