Class: Gain
- Inherits:
-
Object
- Object
- Gain
- Defined in:
- lib/gain.rb,
lib/gain/version.rb
Constant Summary collapse
- VERSION =
"0.3"- @@progress_count =
0
Instance Attribute Summary collapse
-
#progress_print ⇒ Object
readonly
Returns the value of attribute progress_print.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #finish_progress ⇒ Object
-
#initialize(args) ⇒ Gain
constructor
A new instance of Gain.
- #progress ⇒ Object
Constructor Details
#initialize(args) ⇒ Gain
Returns a new instance of Gain.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gain.rb', line 9 def initialize(args) args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end @@progress_count = 0 @progress_print = 1 if @progress_print == nil @@progress_mod = (@total * @progress_print.to_f / 100.0).to_i if @@progress_mod > 1.0 @@progress_mod = @@progress_mod.to_i else @@progress_mod = 1 end @progress_print.to_s.include?(".") ? @@round = @progress_print.to_s.split(".")[1].length : @@round = 0 puts @title if @title != nil end |
Instance Attribute Details
#progress_print ⇒ Object (readonly)
Returns the value of attribute progress_print.
4 5 6 |
# File 'lib/gain.rb', line 4 def progress_print @progress_print end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/gain.rb', line 4 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
4 5 6 |
# File 'lib/gain.rb', line 4 def total @total end |
Instance Method Details
#finish_progress ⇒ Object
36 37 38 |
# File 'lib/gain.rb', line 36 def finish_progress puts "Complete progress" end |
#progress ⇒ Object
29 30 31 32 33 34 |
# File 'lib/gain.rb', line 29 def progress @@progress_count += 1 puts "#{(@@progress_count / @total.to_f * 100).round(@@round)}%" if @@progress_count % @@progress_mod == 0 finish_progress if @@progress_count == @total end |