Class: RassKey::Line

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Line

Returns a new instance of Line.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rasskey/line.rb', line 20

def initialize(options = {})
  options = {
    :line_length => RassKey::Line.default_length,
    :padding => RassKey::Line.default_padding,
    :glyph => RassKey::Line.default_glyph,
    :orientation => RassKey::Line.default_orientation
  }.merge(options)

  self.line_length = options[:line_length]
  self.padding = options[:padding]
  self.glyph = options[:glyph]
  self.orientation = options[:orientation]

  super()
end

Class Attribute Details

.default_glyphObject

Returns the value of attribute default_glyph.



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

def default_glyph
  @default_glyph
end

.default_lengthObject

Returns the value of attribute default_length.



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

def default_length
  @default_length
end

.default_orientationObject

Returns the value of attribute default_orientation.



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

def default_orientation
  @default_orientation
end

.default_paddingObject

Returns the value of attribute default_padding.



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

def default_padding
  @default_padding
end

Instance Attribute Details

#glyphObject

Returns the value of attribute glyph.



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

def glyph
  @glyph
end

#line_lengthObject

Returns the value of attribute line_length.



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

def line_length
  @line_length
end

#orientationObject

Returns the value of attribute orientation.



18
19
20
# File 'lib/rasskey/line.rb', line 18

def orientation
  @orientation
end

#paddingObject

Returns the value of attribute padding.



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

def padding
  @padding
end

Instance Method Details

#draw(data) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rasskey/line.rb', line 36

def draw(data)
  @glyph.length == 1 ? (@glyph = @glyph) : (@glyph = @glyph[0,1])
  spacing = " " * @padding || " "
  line_text = "#{spacing}#{data}#{spacing}"
  begin
    content_line = "#{@glyph * ((@line_length - line_text.length)/2)}#{line_text}#{@glyph * ((@line_length - line_text.length)/2)}"
  rescue
    puts "line length must be larger to accomodate text"
  end
  case @orientation
    when "horizontal"
      content_line
    when "vertical"
      self.vertical(content_line)
    else
      puts "unknown orientation. Should be vertical or horizontal"
  end
end

#vertical(data) ⇒ Object



55
56
57
# File 'lib/rasskey/line.rb', line 55

def vertical(data)
  data.split(//).join("\n")
end