tuvi 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -62,6 +62,27 @@ Finally, after all the steps have been declared (but still within the class), th
62
62
 
63
63
  You can run this file like any other Ruby file, using `ruby filename.rb`.
64
64
 
65
+ You can also add any custom Ruby code by placing it block passed to the `code` method. Also note that variables should be set as globals. For example:
66
+
67
+ step 1 do
68
+ code {$steps = 1}
69
+ message "Welcome to KrazyMaze. Will you ever get out? BWAAHAAA! You have a choice to make: Go right or left"
70
+ answer "right", 2
71
+ answer "left", 3
72
+ end
73
+
74
+ step 2 do
75
+ code do
76
+ $steps += 1
77
+ puts "You have taken #{$steps} steps."
78
+ end
79
+ message "You're in the middle of the maze. Go right or left or straight."
80
+ answer "right", 3
81
+ answer "left", 4
82
+ answer "straight", 3
83
+ end
84
+
85
+
65
86
  ## Contributing
66
87
 
67
88
  1. Fork it
data/example_program.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  require_relative 'lib/tuvi.rb'
2
2
 
3
3
  step 1 do
4
+ code {$x = "hello"}
4
5
  message "This is Step 1. Type yes to go to Step 2. Type no to go to Step 3."
5
6
  answer "Yes", 2
6
7
  answer "No", 3
7
8
  end
8
9
 
9
10
  step 2 do
11
+ code {puts $x}
10
12
  message "This is Step 2. Type hi to go to Step 3. Type bye to go to step 1."
11
13
  answer "Hi", 3
12
14
  answer "Bye", 1
data/lib/tuvi/step.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  class Step
2
2
 
3
- attr_accessor :position, :answer_paths, :exit_program
3
+ attr_accessor :position, :answer_paths, :exit_program, :code_blocks
4
4
 
5
5
  def initialize(position, &block)
6
6
  @position = position
7
7
  @answer_paths = {}
8
+ @code_blocks = []
8
9
  instance_eval(&block) if block_given?
9
10
  end
10
11
 
@@ -28,4 +29,8 @@ class Step
28
29
  "You can type one of the following: [#{@answer_paths.keys.join(", ")}]"
29
30
  end
30
31
 
32
+ def code(&block)
33
+ code_blocks << block
34
+ end
35
+
31
36
  end
data/lib/tuvi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tuvi
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/tuvi.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative "tuvi/version"
2
2
  require_relative "tuvi/step"
3
+ require 'ostruct'
3
4
 
4
5
  module Tuvi
5
6
 
@@ -16,6 +17,9 @@ module Tuvi
16
17
  end
17
18
 
18
19
  def execute_step(current_step)
20
+ @steps[current_step].code_blocks.each do |block|
21
+ block.call
22
+ end
19
23
  puts @steps[current_step].get_message
20
24
  exit if @steps[current_step].exit_program
21
25
  puts @steps[current_step].formatted_answers
data/spec/tuvi_spec.rb CHANGED
@@ -56,4 +56,13 @@ describe Tuvi do
56
56
 
57
57
  end
58
58
 
59
+ describe "#code" do
60
+
61
+ it "should add blocks to the step's code_blocks" do
62
+ @program.step(1){code {puts "Hello"} }
63
+ @program.instance_eval{@steps[1]}.code_blocks[0].should be_a Proc
64
+ end
65
+
66
+ end
67
+
59
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuvi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -96,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  segments:
98
98
  - 0
99
- hash: 3499381177603921583
99
+ hash: 213786611821158706
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  none: false
102
102
  requirements:
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  segments:
107
107
  - 0
108
- hash: 3499381177603921583
108
+ hash: 213786611821158706
109
109
  requirements: []
110
110
  rubyforge_project:
111
111
  rubygems_version: 1.8.25