Class: ProgressBar::Calculators::Length

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-progressbar/calculators/length.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Length

Returns a new instance of Length.



8
9
10
11
12
# File 'lib/ruby-progressbar/calculators/length.rb', line 8

def initialize(options = {})
  self.length_override = options[:length]
  self.output          = options[:output]
  self.current_length  = nil
end

Instance Attribute Details

#current_lengthObject

Returns the value of attribute current_length.



5
6
7
# File 'lib/ruby-progressbar/calculators/length.rb', line 5

def current_length
  @current_length
end

#length_overrideObject

Returns the value of attribute length_override.



4
5
6
# File 'lib/ruby-progressbar/calculators/length.rb', line 4

def length_override
  @length_override
end

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/ruby-progressbar/calculators/length.rb', line 5

def output
  @output
end

Instance Method Details

#calculate_lengthObject



25
26
27
# File 'lib/ruby-progressbar/calculators/length.rb', line 25

def calculate_length
  length_override || terminal_width || 80
end

#lengthObject



14
15
16
# File 'lib/ruby-progressbar/calculators/length.rb', line 14

def length
  current_length || reset_length
end

#length_changed?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/ruby-progressbar/calculators/length.rb', line 18

def length_changed?
  previous_length     = current_length
  self.current_length = calculate_length

  previous_length != current_length
end

#reset_lengthObject



29
30
31
# File 'lib/ruby-progressbar/calculators/length.rb', line 29

def reset_length
  self.current_length = calculate_length
end