Class: Dogsay::TextBox
- Inherits:
-
Object
- Object
- Dogsay::TextBox
- Includes:
- AsciiArt
- Defined in:
- lib/dogsay/text_box.rb
Instance Attribute Summary collapse
-
#justify ⇒ Object
readonly
Returns the value of attribute justify.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#text_width ⇒ Object
readonly
Returns the value of attribute text_width.
Attributes included from AsciiArt
Instance Method Summary collapse
-
#initialize(text, opts = {}) ⇒ TextBox
constructor
A new instance of TextBox.
Methods included from AsciiArt
Constructor Details
#initialize(text, opts = {}) ⇒ TextBox
Returns a new instance of TextBox.
4 5 6 7 8 9 10 11 |
# File 'lib/dogsay/text_box.rb', line 4 def initialize(text, opts={}) @text_width = opts.fetch(:text_width, 40) @separator = opts.fetch(:strip, false) ? ' ' : / / @justify = opts.fetch(:justify, :center) max_width = text.split("\n").map(&:length).max @raw = text.boxed(max_width + 4, justify: :ljust) @ascii = text.space_at(text_width - 4, on: separator).wrap(text_width - 4).boxed(text_width, justify: justify) end |
Instance Attribute Details
#justify ⇒ Object (readonly)
Returns the value of attribute justify.
3 4 5 |
# File 'lib/dogsay/text_box.rb', line 3 def justify @justify end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
3 4 5 |
# File 'lib/dogsay/text_box.rb', line 3 def raw @raw end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
3 4 5 |
# File 'lib/dogsay/text_box.rb', line 3 def separator @separator end |
#text_width ⇒ Object (readonly)
Returns the value of attribute text_width.
3 4 5 |
# File 'lib/dogsay/text_box.rb', line 3 def text_width @text_width end |