Class: Dogsay::TextBox

Inherits:
Object
  • Object
show all
Includes:
AsciiArt
Defined in:
lib/dogsay/text_box.rb

Instance Attribute Summary collapse

Attributes included from AsciiArt

#ascii

Instance Method Summary collapse

Methods included from AsciiArt

#add_art

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

#justifyObject (readonly)

Returns the value of attribute justify.



3
4
5
# File 'lib/dogsay/text_box.rb', line 3

def justify
  @justify
end

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'lib/dogsay/text_box.rb', line 3

def raw
  @raw
end

#separatorObject (readonly)

Returns the value of attribute separator.



3
4
5
# File 'lib/dogsay/text_box.rb', line 3

def separator
  @separator
end

#text_widthObject (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