Class: Turbine::Queue
- Inherits:
-
Object
- Object
- Turbine::Queue
- Includes:
- Enumerable
- Defined in:
- lib/turbine/queue.rb
Instance Method Summary collapse
- #<<(duration) ⇒ Object
- #clear ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #entries ⇒ Object
-
#initialize(dir = Turbine::Application.config_dir) ⇒ Queue
constructor
A new instance of Queue.
- #sum ⇒ Object
Constructor Details
#initialize(dir = Turbine::Application.config_dir) ⇒ Queue
Returns a new instance of Queue.
5 6 7 |
# File 'lib/turbine/queue.rb', line 5 def initialize(dir=Turbine::Application.config_dir) @file = "#{dir}/queue" end |
Instance Method Details
#<<(duration) ⇒ Object
9 10 11 12 |
# File 'lib/turbine/queue.rb', line 9 def <<(duration) File.open(@file, "a") { |f| f.puts(duration.to_s)} self end |
#clear ⇒ Object
36 37 38 |
# File 'lib/turbine/queue.rb', line 36 def clear FileUtils.rm_f(@file) end |
#each ⇒ Object
24 25 26 |
# File 'lib/turbine/queue.rb', line 24 def each entries.each { |e| yield(e) } end |
#empty? ⇒ Boolean
14 15 16 |
# File 'lib/turbine/queue.rb', line 14 def empty? !File.exist?(@file) end |
#entries ⇒ Object
18 19 20 21 22 |
# File 'lib/turbine/queue.rb', line 18 def entries return [] if empty? File.read(@file).split("\n").map { |e| e.to_f } end |
#sum ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/turbine/queue.rb', line 28 def sum return 0 if empty? File.foreach(@file).inject(0) do |sum, line| sum + line.to_f end end |