Class: Leg::Tutorial
- Inherits:
-
Object
- Object
- Leg::Tutorial
- Defined in:
- lib/leg/tutorial.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Instance Method Summary collapse
- #<<(page) ⇒ Object
- #clear ⇒ Object
-
#initialize(config = nil) ⇒ Tutorial
constructor
A new instance of Tutorial.
- #num_steps ⇒ Object
- #step(number) ⇒ Object
- #transform_diffs(transformers, &progress_block) ⇒ Object
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
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/leg/tutorial.rb', line 3 def config @config end |
#pages ⇒ Object (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 |
#clear ⇒ Object
16 17 18 |
# File 'lib/leg/tutorial.rb', line 16 def clear @pages.clear end |
#num_steps ⇒ Object
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 |