Class: RassKey::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/rasskey/box.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  options = {
    :padding => RassKey::Box.default_padding,
    :glyph => RassKey::Box.default_glyph,
    :caption => RassKey::Box.default_caption
  }.merge(options)

  self.padding = options[:padding]
  self.glyph = options[:glyph]
  self.caption = options[:caption]

  super()
end

Class Attribute Details

.default_captionObject

Returns the value of attribute default_caption.



6
7
8
# File 'lib/rasskey/box.rb', line 6

def default_caption
  @default_caption
end

.default_glyphObject

Returns the value of attribute default_glyph.



5
6
7
# File 'lib/rasskey/box.rb', line 5

def default_glyph
  @default_glyph
end

.default_paddingObject

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

#captionObject

Returns the value of attribute caption.



16
17
18
# File 'lib/rasskey/box.rb', line 16

def caption
  @caption
end

#glyphObject

Returns the value of attribute glyph.



15
16
17
# File 'lib/rasskey/box.rb', line 15

def glyph
  @glyph
end

#paddingObject

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}"
  caption_line = "#{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?
    caption_line = "(#{spacing}#{@caption}#{spacing})"
    box << "#{caption_line}"
  end
  box.join("\n")
end