class GraphicalEditor::Editor
Constants
- REGEX_1_250_RANGE
Public Class Methods
new(output)
click to toggle source
# File lib/graphical_editor/editor.rb, line 8 def initialize(output) @output = output end
Public Instance Methods
execute(cmd)
click to toggle source
# File lib/graphical_editor/editor.rb, line 26 def execute(cmd) case cmd when /^I (#{REGEX_1_250_RANGE}) (#{REGEX_1_250_RANGE})$/ @image = Image.new($1.to_i, $2.to_i) when /^C$/ @image.clear when /^L (#{REGEX_1_250_RANGE}) (#{REGEX_1_250_RANGE}) ([A-Z])$/ @image.colourize($1.to_i, $2.to_i, $3) when /^V (#{REGEX_1_250_RANGE}) (#{REGEX_1_250_RANGE}) (#{REGEX_1_250_RANGE}) ([A-Z])$/ @image.draw_vertical($1.to_i, $2.to_i, $3.to_i, $4) when /^H (#{REGEX_1_250_RANGE}) (#{REGEX_1_250_RANGE}) (#{REGEX_1_250_RANGE}) ([A-Z])$/ @image.draw_horizontal($1.to_i, $2.to_i, $3.to_i, $4) when /^F (#{REGEX_1_250_RANGE}) (#{REGEX_1_250_RANGE}) ([A-Z])$/ @image.fill_region($1.to_i, $2.to_i, $3) when /^S$/ puts @image when /^X$/ exit else puts 'Unknown command' end end
listen()
click to toggle source
# File lib/graphical_editor/editor.rb, line 19 def listen loop do cmd = Readline::readline 'Graphical Editor:> ', true execute(cmd) end end
start()
click to toggle source
# File lib/graphical_editor/editor.rb, line 12 def start @output.puts "*"*100 @output.puts 'Welcome to Graphical Image Editor Session.' @output.puts "*"*100 listen end