Class: Pedicab::P

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

Constant Summary collapse

LIST =
{
  questions: "all unique questions necessary to respond to the following",
  facts: "unique pieces of information within the following",
  entities: "unique named entities within the following"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(k) ⇒ P

Returns a new instance of P.



36
37
38
39
40
# File 'lib/pedicab.rb', line 36

def initialize k
  @id = k
  @ride = Pedicab.ride[k]
  reset!
end

Instance Attribute Details

#outObject

Returns the value of attribute out.



34
35
36
# File 'lib/pedicab.rb', line 34

def out
  @out
end

#rankObject (readonly)

Returns the value of attribute rank.



33
34
35
# File 'lib/pedicab.rb', line 33

def rank
  @rank
end

#responseObject (readonly)

Returns the value of attribute response.



33
34
35
# File 'lib/pedicab.rb', line 33

def response
  @response
end

#tookObject (readonly)

Returns the value of attribute took.



33
34
35
# File 'lib/pedicab.rb', line 33

def took
  @took
end

Instance Method Details

#<<(i) ⇒ Object



146
147
148
# File 'lib/pedicab.rb', line 146

def << i
  dispatch(POKE[i])
end

#[](i) ⇒ Object

process inputs into context.



141
142
143
144
# File 'lib/pedicab.rb', line 141

def [] i
  reset!
  prompt(POKE[i])
end

#chain(i) ⇒ Object

chain links



106
107
108
109
110
111
112
# File 'lib/pedicab.rb', line 106

def chain i
  a = [] 
  LINK.each_pair { |k,v| if @ride.go?(%[A response to the following requires #{k}:\n#{i}]); a << k; end }
  aa = a.compact.shuffle
  puts %[#---[CHAIN]---> #{aa}]
  [ aa.map { |e| LINK.on[e].call(self, i) }, i ].flatten
end

#compile(i) ⇒ Object

compile output



96
97
98
# File 'lib/pedicab.rb', line 96

def compile i
  @ride.go("Expand on the following and outline in plaintext without repeating yourself:\n#{i}").gsub("Outline:\n","").gsub(/\n\n+/, "\n")
end

#dispatch(i) ⇒ Object



60
61
62
# File 'lib/pedicab.rb', line 60

def dispatch i
  @ride.go(i)
end

#done?Boolean

Is response complete?

Returns:

  • (Boolean)


116
117
118
# File 'lib/pedicab.rb', line 116

def done?
  @ride.go?(%["#{@out}" truthfully answers the following:\n#{@prompt}])
end

#each(i, p, &b) ⇒ Object

extract elements from prompt.



128
129
130
# File 'lib/pedicab.rb', line 128

def each i, p, &b
  @took = Benchmark.realtime { @ride.go!(i, p) { |e| b.call(e) } }
end

#extract(i) ⇒ Object

distill input



91
92
93
# File 'lib/pedicab.rb', line 91

def extract i
  @ride.go(%[Distill and outline the following without repeating yourself in the simplest possible terms:\n#{i}])
end

#gate(x, &b) ⇒ Object

if x, continue…



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pedicab.rb', line 66

def gate x, &b
  if @ride.go? ERB.new(x).result(binding)
    if block_given?
      b.call(self)
    else
      return true
    end
  else
    if !block_given?
      return false
    end
  end
end

#intent(i) ⇒ Object

extract intent.



44
45
46
# File 'lib/pedicab.rb', line 44

def intent i
  @intent = @ride.go(%[Respond with only the single word describing the type of the response necessary for the following:\n#{i}])
end

#more(q) ⇒ Object

extract questions and expand into context.



134
135
136
# File 'lib/pedicab.rb', line 134

def more q
  each(LIST[:questions], POKE[q]) { |e| dispatch(%[#{e}\n#{@ride.go(e)}]); }
end

#outline(i) ⇒ Object

integrate



101
102
103
# File 'lib/pedicab.rb', line 101

def outline i
  @ride.go("#{@respond.join("\n")}\nDistill the following into the above outline without repeating yourself:\n#{i}")
end

#prompt(i) ⇒ Object

process prompt into context.



82
83
84
85
86
87
# File 'lib/pedicab.rb', line 82

def prompt i
  @prompt = i
  @took = Benchmark.realtime { @out = dispatch([@response[-1], @prompt].flatten.compact.uniq.join("\n")) }
  @response << @out
  return @out
end

#ready?Boolean

Is intent met by current output?

Returns:

  • (Boolean)


122
123
124
# File 'lib/pedicab.rb', line 122

def ready?
  @ride.go?(%[The following satisfies #{@intent}:\n#{@out}])
end

#reset!Object

reset context.



50
51
52
53
54
55
56
57
58
# File 'lib/pedicab.rb', line 50

def reset!
  @ride.reset!
  @response = []
  @rank = RANK[@id]
  @intent = ""
  @prompt = ""
  @out = ""
  @took = 0      
end