Class: Pedicab::Ride
- Inherits:
-
Object
- Object
- Pedicab::Ride
- Defined in:
- lib/pedicab/ride.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#goal ⇒ Object
Returns the value of attribute goal.
-
#info ⇒ Object
Returns the value of attribute info.
-
#model ⇒ Object
Returns the value of attribute model.
-
#path ⇒ Object
Returns the value of attribute path.
-
#ride ⇒ Object
Returns the value of attribute ride.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tale ⇒ Object
tell the “tale” of the ride.
Instance Method Summary collapse
-
#go(i) ⇒ Object
process input.
-
#go!(i, p, &b) ⇒ Object
process list.
-
#go?(i) ⇒ Boolean
process condition.
-
#initialize(k) ⇒ Ride
constructor
A new instance of Ride.
- #reset! ⇒ Object
Constructor Details
#initialize(k) ⇒ Ride
5 6 7 8 9 |
# File 'lib/pedicab/ride.rb', line 5 def initialize k @id = k @model = 'model' reset! end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/pedicab/ride.rb', line 4 def action @action end |
#goal ⇒ Object
Returns the value of attribute goal.
4 5 6 |
# File 'lib/pedicab/ride.rb', line 4 def goal @goal end |
#info ⇒ Object
Returns the value of attribute info.
4 5 6 |
# File 'lib/pedicab/ride.rb', line 4 def info @info end |
#model ⇒ Object
Returns the value of attribute model.
4 5 6 |
# File 'lib/pedicab/ride.rb', line 4 def model @model end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/pedicab/ride.rb', line 4 def path @path end |
#ride ⇒ Object
Returns the value of attribute ride.
4 5 6 |
# File 'lib/pedicab/ride.rb', line 4 def ride @ride end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/pedicab/ride.rb', line 4 def state @state end |
#tale ⇒ Object
tell the “tale” of the ride.
19 20 21 |
# File 'lib/pedicab/ride.rb', line 19 def tale @tale end |
Instance Method Details
#go(i) ⇒ Object
process input.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pedicab/ride.rb', line 32 def go i @path << "go #{i}" @state[:action] = "go" @state[:input] = i # puts %[#===============[work]>\n#{i}\n#===============[work]]; Pedicab.on[:work].call(self) @state[:output] = rider(role: 'user', model: 'work', content: "#{@info}#{tale}#{i}") @ride << @state @state[:output].gsub(/\n+/, "\n") end |
#go!(i, p, &b) ⇒ Object
process list
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pedicab/ride.rb', line 62 def go! i, p, &b @path << "with #{i} of #{p}" @state[:action] = "go! fork" @state[:input] = %[#{@info}#{tale}List only #{i} unnumbered without repeating yourself:\n#{p}] Pedicab.on[:fork].call(self) @state[:list] = rider(role: 'user', model: 'fork', content: @state[:input]).split("\n").uniq.map { |e| if e.strip.length > 0; # puts %[#----------[fork]>\nfor: #{i}\nin: #{p}\nat: #{e}\n#----------[fork]]; Pedicab.on[:with].call(self); b.call(e.strip); end; } @ride << @state @state[:list] end |
#go?(i) ⇒ Boolean
process condition
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pedicab/ride.rb', line 45 def go? i @path << "go? #{i}" @state[:action] = "go?" @state[:input] = i @state[:yes] = false # puts %[#>>>>>[gate]>\n#{i}\n#>>>>>[gate]]; Pedicab.on[:gate].call(self) if rider(role: 'system', model: 'gate', content: %[#{@info}#{tale}if the following statement is true respond 'yes', otherwise respond 'no':\n#{i}], response: 'bool' ) == 'yes' @state[:yes] = true Pedicab.on[:go].call(self) end @ride << @state @state[:yes] end |
#reset! ⇒ Object
10 11 12 13 14 15 |
# File 'lib/pedicab/ride.rb', line 10 def reset! @state = {} @ride = [] @path = [] @info = "" end |