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.



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

def initialize(options)
  self.length_override = options[:length]
  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

Instance Method Details

#calculate_lengthObject



23
24
25
# File 'lib/ruby-progressbar/calculators/length.rb', line 23

def calculate_length
  length_override || terminal_width || 80
end

#lengthObject



12
13
14
# File 'lib/ruby-progressbar/calculators/length.rb', line 12

def length
  current_length || reset_length
end

#length_changed?Boolean

Returns:

  • (Boolean)


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

def length_changed?
  previous_length     = current_length
  self.current_length = calculate_length

  previous_length != current_length
end

#reset_lengthObject



27
28
29
# File 'lib/ruby-progressbar/calculators/length.rb', line 27

def reset_length
  self.current_length = calculate_length
end