Class: Barr::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/barr/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Block

Returns a new instance of Block.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/barr/block.rb', line 5

def initialize(opts = {})
  reassign_deprecated_option opts, :fcolor, :fgcolor
  reassign_deprecated_option opts, :bcolor, :bgcolor
  @align = opts[:align] || :l
  @bgcolor = opts[:bgcolor] || '-'
  @fgcolor = opts[:fgcolor] || '-'
  @icon = opts[:icon] || ''
  @interval = opts[:interval] || 5

  @output = ''
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



3
4
5
# File 'lib/barr/block.rb', line 3

def align
  @align
end

#bgcolorObject (readonly)

Returns the value of attribute bgcolor.



3
4
5
# File 'lib/barr/block.rb', line 3

def bgcolor
  @bgcolor
end

#fgcolorObject (readonly)

Returns the value of attribute fgcolor.



3
4
5
# File 'lib/barr/block.rb', line 3

def fgcolor
  @fgcolor
end

#iconObject (readonly)

Returns the value of attribute icon.



3
4
5
# File 'lib/barr/block.rb', line 3

def icon
  @icon
end

#intervalObject (readonly)

Returns the value of attribute interval.



3
4
5
# File 'lib/barr/block.rb', line 3

def interval
  @interval
end

#outputObject (readonly)

Returns the value of attribute output.



3
4
5
# File 'lib/barr/block.rb', line 3

def output
  @output
end

Instance Method Details

#<<(str) ⇒ Object



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

def <<(str)
  @output << str
end

#colorsObject



21
22
23
# File 'lib/barr/block.rb', line 21

def colors
  "%{B#{bgcolor}}%{F#{fgcolor}}"
end

#destroyObject



39
# File 'lib/barr/block.rb', line 39

def destroy; destroy!; end

#destroy!Object



29
30
# File 'lib/barr/block.rb', line 29

def destroy!
end

#drawObject



25
26
27
# File 'lib/barr/block.rb', line 25

def draw
  "#{colors} #{icon} #{@output} #{reset_colors}"
end

#reassign_deprecated_option(opts, old, new) ⇒ Object



41
42
43
44
45
46
# File 'lib/barr/block.rb', line 41

def reassign_deprecated_option opts, old, new
  if opts[new].nil? && !opts[old].nil?
    STDERR.puts "Warning: the '#{old}' option will soon be deprecated in favour of '#{new}'. \n Please update your script."
    opts[new] = opts[old]
  end
end

#updateObject

Backwards compatiblity methods. can’t use alias/alias_method as they don’t trickle down to subclasses



38
# File 'lib/barr/block.rb', line 38

def update; update!; end

#update!Object



32
33
# File 'lib/barr/block.rb', line 32

def update!
end