0
0
Fork 0

Improvement of Rubella::Output::ASCII

I've fixed a bug, which causes, the 11 than 10 lines tho the outputted data.
Now the empty line at the end is removed.
Corresponding to the base class create now returns self.
I also added some documentation.
This commit is contained in:
Stormwind 2015-02-24 21:30:14 +01:00
parent f5efd50d9f
commit 600443ddd4
1 changed files with 37 additions and 1 deletions

View File

@ -3,10 +3,29 @@ require "rubella/output/base"
module Rubella
module Output
# Creates a ascii art representation of the given storage data.
# In @data will a ordenary String be stored. Print the String to your
# output field and it will shows a nice ascii art graphic.
# There are also different ascii art themes available. Including the
# possibility to add own themes.
# You only need to push an Array within 10 chars for the representation
# into the :symbols Hash. Then you can select it with set the used_symbols
# variable to you theme name.
#
# TODO Use setted field_size for representation
#
class ASCII < Base
attr_accessor :symbols
attr_reader :used_symbols
# Constructor
# Sets the default field_size to 1.
# Also sets the used ascii art theme to "shades_ascii". See the
# used_symbols= for further information.
#
# @param field_size int Used chars for one value
# @return Rubella::Output::ASCII
#
def initialize field_size = 1
@symbols = Hash.new
@symbols["shades"] =
@ -22,6 +41,17 @@ module Rubella
super field_size
end
# Sets the used ascii theme by the given name.
# The theme must exist. You can also choose your custom theme here.
# The at default avaliable themes are:
# * shades
# * shades_ascii
# * ascii
# * numbers
#
# @param value String The theme name
# @raise ArgumentError
#
def used_symbols= value
if @symbols.has_key? value
@used_symbols = value
@ -31,6 +61,11 @@ module Rubella
@symbols.keys.join(", ")
end
# Creates an ascii art representation of the given storage data.
#
# @param storage Rubella::Storage
# @return Rubella::Storage::ASCII
#
def create storage
buckets = storage.data[0].length
# columns = storage.data.length
@ -41,7 +76,7 @@ module Rubella
# start drawing the damn thing
ascii_arr = []
0.upto(buckets).each { |i| ascii_arr[i] = "" }
0.upto(buckets-1).each { |i| ascii_arr[i] = "" }
storage.data.each do |point|
i = 0
@ -60,6 +95,7 @@ module Rubella
end
@data = ascii_arr.join("\n")
self
end
end