Class: ProgressBar::Format::Molecule

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-progressbar/format/molecule.rb

Constant Summary collapse

MOLECULES =
{
  :t => [:title_comp,   :title],
  :T => [:title_comp,   :title],
  :c => [:progressable, :progress],
  :C => [:progressable, :total],
  :p => [:percentage,   :percentage],
  :P => [:percentage,   :percentage_with_precision],
  :j => [:percentage,   :justified_percentage],
  :J => [:percentage,   :justified_percentage_with_precision],
  :a => [:time,         :elapsed_with_label],
  :e => [:time,         :estimated_with_unknown_oob],
  :E => [:time,         :estimated_with_friendly_oob],
  :f => [:time,         :estimated_with_no_oob],
  :B => [:bar,          :complete_bar],
  :b => [:bar,          :bar],
  :w => [:bar,          :bar_with_percentage],
  :i => [:bar,          :incomplete_space],
  :r => [:rate,         :rate_of_change],
  :R => [:rate,         :rate_of_change_with_precision],
}
BAR_MOLECULES =
%w{w B b i}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(letter) ⇒ Molecule

Returns a new instance of Molecule.



30
31
32
33
# File 'lib/ruby-progressbar/format/molecule.rb', line 30

def initialize(letter)
  self.key         = letter
  self.method_name = MOLECULES.fetch(key.to_sym)
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



27
28
29
# File 'lib/ruby-progressbar/format/molecule.rb', line 27

def key
  @key
end

#method_nameObject

Returns the value of attribute method_name.



27
28
29
# File 'lib/ruby-progressbar/format/molecule.rb', line 27

def method_name
  @method_name
end

Instance Method Details

#bar_molecule?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/ruby-progressbar/format/molecule.rb', line 35

def bar_molecule?
  BAR_MOLECULES.include? key
end

#full_keyObject



43
44
45
# File 'lib/ruby-progressbar/format/molecule.rb', line 43

def full_key
  "%#{key}"
end

#lookup_value(environment, length = 0) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/ruby-progressbar/format/molecule.rb', line 47

def lookup_value(environment, length = 0)
  component = environment.send(method_name[0])

  if bar_molecule?
    component.send(method_name[1], length).to_s
  else
    component.send(method_name[1]).to_s
  end
end

#non_bar_molecule?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ruby-progressbar/format/molecule.rb', line 39

def non_bar_molecule?
  !bar_molecule?
end