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.



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

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

#managerObject

Returns the value of attribute manager.



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

def manager
  @manager
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



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

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

#colorsObject



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

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

#destroyObject



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

def destroy; destroy!; end

#destroy!Object



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

def destroy!
end

#drawObject



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

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

#reassign_deprecated_option(opts, old, new) ⇒ Object



47
48
49
50
51
52
# File 'lib/barr/block.rb', line 47

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

#tmp_filenameObject



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

def tmp_filename
  @tmp_filename ||= "/tmp/#{SecureRandom.uuid}-#{self.class.name.gsub(/::/, "-")}-#{SecureRandom.urlsafe_base64}"
  return @tmp_filename
end

#updateObject

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



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

def update; update!; end

#update!Object



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

def update!
end