Class: ToolmanS
- Inherits:
-
Object
- Object
- ToolmanS
- Defined in:
- lib/toolman/toolS.rb
Instance Method Summary collapse
-
#initialize ⇒ ToolmanS
constructor
A new instance of ToolmanS.
- #loading_bar(nowPoint, endPoint) ⇒ Object
- #loading_bar_add ⇒ Object
- #loading_bar_end ⇒ Object
- #puts ⇒ Object
- #say(data) ⇒ Object
Constructor Details
#initialize ⇒ ToolmanS
Returns a new instance of ToolmanS.
4 5 6 7 8 9 10 |
# File 'lib/toolman/toolS.rb', line 4 def initialize @tempPoint = 0 @circle = ["|","\\","-","/"] @circleSize = @circle.size @loadBarPid = 0 @colorMechine = Color.new end |
Instance Method Details
#loading_bar(nowPoint, endPoint) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/toolman/toolS.rb', line 23 def (nowPoint,endPoint) read, write = IO.pipe @loadBarPid = fork { write.close continue = true sleep_time = 1.0/7.0 index = 0 while(continue) do p = (( (nowPoint*1.0) / endPoint) * 100).floor print "\r" print " \r" print "%5d%s%3s%-3s" % [p,"%","#{@circle[@tempPoint]}",""] @tempPoint = (@tempPoint + 1) % @circleSize if p == 100 print "\r" print " \r" print "%5d%s%3s%-3s" % [p,"%","",""] read.close exit(0) end sleep(sleep_time) s = IO.select([read],[],[],sleep_time) if s result = read.read(1) if result if result.to_i == 1 nowPoint += 1 elsif result.to_i == 0 puts "" puts "Early break..." read.close exit(0) end end index += 1 end end } read.close @write = write # Process.wait(@loadBarPid) # puts "hi" end |
#loading_bar_add ⇒ Object
72 73 74 |
# File 'lib/toolman/toolS.rb', line 72 def () @write.write(1) end |
#loading_bar_end ⇒ Object
76 77 78 |
# File 'lib/toolman/toolS.rb', line 76 def () @write.write(0) end |
#puts ⇒ Object
12 13 14 |
# File 'lib/toolman/toolS.rb', line 12 def puts @colorMechine end |
#say(data) ⇒ Object
17 18 19 20 21 |
# File 'lib/toolman/toolS.rb', line 17 def say(data) puts "\n>>>>>>>>>>>>>>>>>Messange>>>>>>>>>>>>>>>>>" puts "#{data}" puts ">>>>>>>>>>>>>>>>>Messange>>>>>>>>>>>>>>>>>\n" end |