diff --git a/lib/rubella/output/ascii.rb b/lib/rubella/output/ascii.rb index 514af0b..de9bc54 100644 --- a/lib/rubella/output/ascii.rb +++ b/lib/rubella/output/ascii.rb @@ -1,7 +1,9 @@ +require "rubella/output/base" + module Rubella module Output - class ASCII + class ASCII < Base attr_accessor :symbols attr_reader :used_symbols @@ -16,8 +18,8 @@ module Rubella @symbols["numbers"] = [" ", "1", "2", "3", "4", "5", "6", "7", "8", "9"] - @field_size = field_size self.used_symbols = "shades_ascii" + super field_size end def used_symbols= value @@ -30,19 +32,18 @@ module Rubella end def create storage - parsed_list = storage.data - buckets = parsed_list[0].length - columns = parsed_list.length + buckets = storage.data[0].length + # columns = storage.data.length # image size - x = columns*@field_size - y = buckets*@field_size + # x = columns*@field_size + # y = buckets*@field_size # start drawing the damn thing ascii_arr = [] 0.upto(buckets).each { |i| ascii_arr[i] = "" } - parsed_list.each do |point| + storage.data.each do |point| i = 0 point.reverse.each do |part| part = (part*10).to_i @@ -58,7 +59,7 @@ module Rubella end end - ascii_arr.join("\n") + @data = ascii_arr.join("\n") end end diff --git a/lib/rubella/output/base.rb b/lib/rubella/output/base.rb index 841d91f..42e2a81 100644 --- a/lib/rubella/output/base.rb +++ b/lib/rubella/output/base.rb @@ -2,6 +2,12 @@ module Rubella module Output class Base + attr_accessor :field_size + attr_reader :data + + def initialize field_size = 15 + @field_size = field_size + end end end diff --git a/lib/rubella/output/image.rb b/lib/rubella/output/image.rb index a84fcb1..cbcb6d1 100644 --- a/lib/rubella/output/image.rb +++ b/lib/rubella/output/image.rb @@ -1,19 +1,14 @@ +require "rubella/output/base" require 'RMagick' module Rubella module Output - class Image - attr_accessor :field_size - - def initialize field_size = 15 - @field_size = field_size - end + class Image < Base def create storage - parsed_list = storage.data - buckets = parsed_list[0].length - columns = parsed_list.length + buckets = storage.data[0].length + columns = storage.data.length # image size x = columns*@field_size @@ -23,7 +18,7 @@ module Rubella loadImg = Magick::Image.new(x, y) { self.background_color = "white" } i = 0 - parsed_list.each do |point| + storage.data.each do |point| j = 0 point.reverse.each do |part| # draw a red rectangle on the white background @@ -45,7 +40,7 @@ module Rubella i = i + 1 end - loadImg.display + @data = loadImg end