Class: Leg::Tutorial

Inherits:
Object
  • Object
show all
Defined in:
lib/leg/tutorial.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Tutorial

Returns a new instance of Tutorial.



6
7
8
9
# File 'lib/leg/tutorial.rb', line 6

def initialize(config = nil)
  @config = config
  @pages = []
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/leg/tutorial.rb', line 3

def config
  @config
end

#pagesObject (readonly)

Returns the value of attribute pages.



4
5
6
# File 'lib/leg/tutorial.rb', line 4

def pages
  @pages
end

Instance Method Details

#<<(page) ⇒ Object



11
12
13
14
# File 'lib/leg/tutorial.rb', line 11

def <<(page)
  @pages << page
  self
end

#clearObject



16
17
18
# File 'lib/leg/tutorial.rb', line 16

def clear
  @pages.clear
end

#num_stepsObject



30
31
32
# File 'lib/leg/tutorial.rb', line 30

def num_steps
  @pages.map(&:steps).map(&:length).sum
end

#step(number) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/leg/tutorial.rb', line 20

def step(number)
  cur = 1
  @pages.each do |page|
    page.steps.each do |step|
      return step if cur == number
      cur += 1
    end
  end
end

#transform_diffs(transformers, &progress_block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/leg/tutorial.rb', line 34

def transform_diffs(transformers, &progress_block)
  step_num = 1
  @pages.each do |page|
    page.steps.each do |step|
      step.diffs.map! do |diff|
        transformers.inject(diff) do |acc, transformer|
          transformer.transform(acc)
        end
      end
      progress_block.(step_num) if progress_block
      step_num += 1
    end
  end
end