Class: Snaptoken::Tutorial
- Inherits:
-
Object
- Object
- Snaptoken::Tutorial
- Defined in:
- lib/snaptoken/tutorial.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#page_template ⇒ Object
Returns the value of attribute page_template.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#step_template ⇒ Object
Returns the value of attribute step_template.
Instance Method Summary collapse
- #<<(page) ⇒ Object
- #clear ⇒ Object
-
#initialize(config = {}) ⇒ Tutorial
constructor
A new instance of Tutorial.
- #last_synced_at ⇒ Object
- #num_steps ⇒ Object
- #step(number) ⇒ Object
- #synced! ⇒ Object
- #transform_diffs(transformers, &progress_block) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Tutorial
6 7 8 9 10 11 |
# File 'lib/snaptoken/tutorial.rb', line 6 def initialize(config = {}) @config = config @page_template = Snaptoken::DefaultTemplates::PAGE @step_template = Snaptoken::DefaultTemplates::STEP @pages = [] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
2 3 4 |
# File 'lib/snaptoken/tutorial.rb', line 2 def config @config end |
#page_template ⇒ Object
Returns the value of attribute page_template.
3 4 5 |
# File 'lib/snaptoken/tutorial.rb', line 3 def page_template @page_template end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
4 5 6 |
# File 'lib/snaptoken/tutorial.rb', line 4 def pages @pages end |
#step_template ⇒ Object
Returns the value of attribute step_template.
3 4 5 |
# File 'lib/snaptoken/tutorial.rb', line 3 def step_template @step_template end |
Instance Method Details
#<<(page) ⇒ Object
13 14 15 16 |
# File 'lib/snaptoken/tutorial.rb', line 13 def <<(page) @pages << page self end |
#clear ⇒ Object
18 19 20 |
# File 'lib/snaptoken/tutorial.rb', line 18 def clear @pages.clear end |
#last_synced_at ⇒ Object
51 52 53 |
# File 'lib/snaptoken/tutorial.rb', line 51 def last_synced_at File.mtime(last_synced_path) if File.exist?(last_synced_path) end |
#num_steps ⇒ Object
32 33 34 |
# File 'lib/snaptoken/tutorial.rb', line 32 def num_steps @pages.map(&:steps).map(&:length).sum end |
#step(number) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/snaptoken/tutorial.rb', line 22 def step(number) cur = 1 @pages.each do |page| page.steps.each do |step| return step if cur == number cur += 1 end end end |
#synced! ⇒ Object
55 56 57 |
# File 'lib/snaptoken/tutorial.rb', line 55 def synced! FileUtils.touch(last_synced_path) end |
#transform_diffs(transformers, &progress_block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/snaptoken/tutorial.rb', line 36 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 |