Class: RassKey::Box
- Inherits:
-
Object
- Object
- RassKey::Box
- Defined in:
- lib/rasskey/box.rb
Class Attribute Summary collapse
-
.default_caption ⇒ Object
Returns the value of attribute default_caption.
-
.default_glyph ⇒ Object
Returns the value of attribute default_glyph.
-
.default_padding ⇒ Object
Returns the value of attribute default_padding.
Instance Attribute Summary collapse
-
#caption ⇒ Object
Returns the value of attribute caption.
-
#glyph ⇒ Object
Returns the value of attribute glyph.
-
#padding ⇒ Object
Returns the value of attribute padding.
Instance Method Summary collapse
- #draw(data) ⇒ Object
-
#initialize(options = {}) ⇒ Box
constructor
A new instance of Box.
Constructor Details
#initialize(options = {}) ⇒ Box
Returns a new instance of Box.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rasskey/box.rb', line 18 def initialize( = {}) = { :padding => RassKey::Box.default_padding, :glyph => RassKey::Box.default_glyph, :caption => RassKey::Box. }.merge() self.padding = [:padding] self.glyph = [:glyph] self. = [:caption] super() end |
Class Attribute Details
.default_caption ⇒ Object
Returns the value of attribute default_caption.
6 7 8 |
# File 'lib/rasskey/box.rb', line 6 def @default_caption end |
.default_glyph ⇒ Object
Returns the value of attribute default_glyph.
5 6 7 |
# File 'lib/rasskey/box.rb', line 5 def default_glyph @default_glyph end |
.default_padding ⇒ Object
Returns the value of attribute default_padding.
4 5 6 |
# File 'lib/rasskey/box.rb', line 4 def default_padding @default_padding end |
Instance Attribute Details
#caption ⇒ Object
Returns the value of attribute caption.
16 17 18 |
# File 'lib/rasskey/box.rb', line 16 def @caption end |
#glyph ⇒ Object
Returns the value of attribute glyph.
15 16 17 |
# File 'lib/rasskey/box.rb', line 15 def glyph @glyph end |
#padding ⇒ Object
Returns the value of attribute padding.
14 15 16 |
# File 'lib/rasskey/box.rb', line 14 def padding @padding end |
Instance Method Details
#draw(data) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rasskey/box.rb', line 32 def draw(data) @glyph.length == 1 ? (@glyph = @glyph) : (@glyph = @glyph[0,1]) whitespace = " " * ( data.length + (@padding * 2) ) spacing = " " * @padding || " " content_line = "#{@glyph}#{spacing}#{data}#{spacing}#{@glyph}" = "#{spacing}#{@caption}#{spacing}" top = @glyph * content_line.length side = @glyph bottom = @glyph * content_line.length box = [] box << top (@padding/2).times { box << "#{@glyph}#{whitespace}#{@glyph}" } box << "#{content_line}" (@padding/2).times { box << "#{@glyph}#{whitespace}#{@glyph}" } box << bottom unless @caption.nil? = "(#{spacing}#{@caption}#{spacing})" box << "#{}" end box.join("\n") end |