Class: TextChart
- Inherits:
-
Object
- Object
- TextChart
- Defined in:
- lib/text_chart.rb,
lib/text_chart/version.rb
Overview
This is the main class of the text_chart. After calling the #to_s method you’ll receive a string representing the chart, just like this one:
text_chart demonstration Show you how cool this is
73| ###
| ###
67| ### ### ### ###
| ### ### ### ###
54| ### ### ### ### ### ### ###
| ### ### ### ### ### ### ###
44| ### ### ### ### ### ### ### ### ### ###
| ### ### ### ### ### ### ### ### ### ###
33| ### ### ### ### ### ### ### ### ### ### ###
| ### ### ### ### ### ### ### ### ### ### ###
27| ### ### ### ### ### ### ### ### ### ### ### ### ### ### 20| ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### 14| ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### 10| ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
5| ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
----------------------------------------------------------------------------------
Defined Under Namespace
Classes: Designer, Error, SizeCalculator
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#designer ⇒ Object
readonly
Returns the value of attribute designer.
-
#size_calculator ⇒ Object
readonly
Returns the value of attribute size_calculator.
-
#subtitle ⇒ Object
readonly
Returns the value of attribute subtitle.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(title, subtitle, data, colors = false) ⇒ TextChart
constructor
A new instance of TextChart.
- #size_config(key) ⇒ Integer
- #to_s ⇒ String
Constructor Details
#initialize(title, subtitle, data, colors = false) ⇒ TextChart
Returns a new instance of TextChart.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/text_chart.rb', line 36 def initialize(title, subtitle, data, colors = false) raise Error, "`data` cannot be empty" if data.empty? @title = title @subtitle = subtitle @data = data.empty? ? [0] : data.filter(&:positive?) @colors = colors @size_calculator = SizeCalculator.new(self) @designer = Designer.new(self, @size_calculator) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
47 48 49 |
# File 'lib/text_chart.rb', line 47 def data @data end |
#designer ⇒ Object (readonly)
Returns the value of attribute designer.
47 48 49 |
# File 'lib/text_chart.rb', line 47 def designer @designer end |
#size_calculator ⇒ Object (readonly)
Returns the value of attribute size_calculator.
47 48 49 |
# File 'lib/text_chart.rb', line 47 def size_calculator @size_calculator end |
#subtitle ⇒ Object (readonly)
Returns the value of attribute subtitle.
47 48 49 |
# File 'lib/text_chart.rb', line 47 def subtitle @subtitle end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
47 48 49 |
# File 'lib/text_chart.rb', line 47 def title @title end |
Instance Method Details
#size_config(key) ⇒ Integer
62 63 64 |
# File 'lib/text_chart.rb', line 62 def size_config(key) SIZE_CONFIG[key] end |
#to_s ⇒ String
50 51 52 53 54 55 56 57 58 |
# File 'lib/text_chart.rb', line 50 def to_s result = @designer.draw_axis && @designer. && @designer.draw_header result = @designer.paint if @colors result.join end |