Class: Nmg::Type::Maintenance

Inherits:
Base
  • Object
show all
Defined in:
lib/nmg/type/maintenance.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_json

Class Method Details

.generate(count, options = {}, generator = Random.new) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nmg/type/maintenance.rb', line 11

def self.generate(count, options = {}, generator = Random.new)
  options = {from: 1, to: 20, step: {min: 10, max: 50}}.merge(options)

  arr = []
  duration = (options[:from]..options[:to])
  step = (options[:step][:min]..options[:step][:max])

  arr << Maintenance.new(start: generator.rand(step),
                         duration: generator.rand(duration))

  count.to_i.times do
    last = arr.last

    arr << Maintenance.new(start: last.stop + generator.rand(step),
                           duration: generator.rand(duration))
  end

  arr
end

Instance Method Details

#stopObject



7
8
9
# File 'lib/nmg/type/maintenance.rb', line 7

def stop
  start + duration
end