Class: TryRuby::Script
- Inherits:
-
Object
- Object
- TryRuby::Script
- Defined in:
- lib/try_ruby/script.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #continue? ⇒ Boolean
- #current_message ⇒ Object (also: #current)
- #first? ⇒ Boolean
-
#initialize(filename) ⇒ Script
constructor
A new instance of Script.
- #intro ⇒ Object
- #last? ⇒ Boolean
- #length ⇒ Object
- #messages ⇒ Object
- #next ⇒ Object
- #outro ⇒ Object
- #previous ⇒ Object
Constructor Details
#initialize(filename) ⇒ Script
Returns a new instance of Script.
5 6 7 8 9 |
# File 'lib/try_ruby/script.rb', line 5 def initialize(filename) @position = 0 @script = JSON.parse(File.read(filename)) end |
Instance Attribute Details
#position ⇒ Object (readonly)
Returns the value of attribute position.
3 4 5 |
# File 'lib/try_ruby/script.rb', line 3 def position @position end |
Instance Method Details
#continue? ⇒ Boolean
25 26 27 |
# File 'lib/try_ruby/script.rb', line 25 def continue? .continue? end |
#current_message ⇒ Object Also known as: current
15 16 17 |
# File 'lib/try_ruby/script.rb', line 15 def [@position] end |
#first? ⇒ Boolean
41 42 43 |
# File 'lib/try_ruby/script.rb', line 41 def first? @position == 0 end |
#intro ⇒ Object
29 30 31 |
# File 'lib/try_ruby/script.rb', line 29 def intro .first end |
#last? ⇒ Boolean
37 38 39 |
# File 'lib/try_ruby/script.rb', line 37 def last? @position == (length-1) end |
#length ⇒ Object
21 22 23 |
# File 'lib/try_ruby/script.rb', line 21 def length .length end |
#messages ⇒ Object
11 12 13 |
# File 'lib/try_ruby/script.rb', line 11 def @messages ||= @script["messages"].map {|attributes| Message.new(attributes)} end |
#next ⇒ Object
45 46 47 48 |
# File 'lib/try_ruby/script.rb', line 45 def next @position += 1 unless last? current end |
#outro ⇒ Object
33 34 35 |
# File 'lib/try_ruby/script.rb', line 33 def outro .last end |
#previous ⇒ Object
50 51 52 53 |
# File 'lib/try_ruby/script.rb', line 50 def previous @position -= 1 unless first? current end |