Class: Moist::Steps::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/moist/steps/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(campaign, steps) ⇒ Collection

Returns a new instance of Collection.



11
12
13
14
# File 'lib/moist/steps/collection.rb', line 11

def initialize(campaign, steps)
  @campaign = campaign
  @steps = sort(steps)
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



10
11
12
# File 'lib/moist/steps/collection.rb', line 10

def steps
  @steps
end

Class Method Details

.for(campaign) ⇒ Object



6
7
8
# File 'lib/moist/steps/collection.rb', line 6

def self.for(campaign)
  new(campaign, ::Moist.step_registry[campaign.to_slug])
end

Instance Method Details

#[](val) ⇒ Object



24
25
26
# File 'lib/moist/steps/collection.rb', line 24

def [](val)
  @steps[val]
end

#each(&block) ⇒ Object



16
17
18
# File 'lib/moist/steps/collection.rb', line 16

def each(&block)
  @steps.each { |step| block.call(step) }
end

#find(step_number) ⇒ Object



28
29
30
31
32
# File 'lib/moist/steps/collection.rb', line 28

def find(step_number)
  return nil unless step_number.is_a?(Integer)

  steps.detect { |step| step.options[:step] == step_number } || find_next(step_number)
end

#find_next(step_number) ⇒ Object



34
35
36
37
38
# File 'lib/moist/steps/collection.rb', line 34

def find_next(step_number)
  return nil unless step_number.is_a?(Integer)

  steps.detect { |step| step.options[:step] > step_number } || last_step?(step_number)
end

#sizeObject



20
21
22
# File 'lib/moist/steps/collection.rb', line 20

def size
  @steps.size
end