Class: Pedicab::Ride

Inherits:
Object
  • Object
show all
Defined in:
lib/pedicab/ride.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/pedicab/ride.rb', line 4

def action
  @action
end

#goalObject

Returns the value of attribute goal.



4
5
6
# File 'lib/pedicab/ride.rb', line 4

def goal
  @goal
end

#infoObject

Returns the value of attribute info.



4
5
6
# File 'lib/pedicab/ride.rb', line 4

def info
  @info
end

#modelObject

Returns the value of attribute model.



4
5
6
# File 'lib/pedicab/ride.rb', line 4

def model
  @model
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/pedicab/ride.rb', line 4

def path
  @path
end

#rideObject

Returns the value of attribute ride.



4
5
6
# File 'lib/pedicab/ride.rb', line 4

def ride
  @ride
end

#stateObject

Returns the value of attribute state.



4
5
6
# File 'lib/pedicab/ride.rb', line 4

def state
  @state
end

#taleObject

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