ceml 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.4
1
+ 0.7.5
data/ceml.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ceml}
8
- s.version = "0.7.4"
8
+ s.version = "0.7.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Edelman"]
@@ -7,7 +7,10 @@ module CEML
7
7
  def roles_to_cast(script)
8
8
  return [] unless type == :await
9
9
  roles.list.map do |r|
10
- c = Criteria.new(r.qualifiers, [], radius ? [:city] : [], radius, timewindow)
10
+ matching = []
11
+ matching << matching_text if matching_text
12
+ matching += [:city] if radius
13
+ c = Criteria.new(r.qualifiers, [], matching, radius, timewindow)
11
14
  Role.new r.name, c, r.min..r.max, []
12
15
  end
13
16
  end
@@ -30,6 +33,15 @@ module CEML
30
33
  modifiers.elements.select{ |m| m.respond_to? :duration }.first
31
34
  end
32
35
 
36
+ def with_matching_phrase
37
+ return if modifiers.empty?
38
+ modifiers.elements.select{ |m| m.respond_to? :thing }.first
39
+ end
40
+
41
+ def matching_text
42
+ with_matching_phrase && with_matching_phrase.thing.text_value
43
+ end
44
+
33
45
  def timewindow
34
46
  over_phrase && over_phrase.duration.seconds
35
47
  end
data/lib/ceml/driver.rb CHANGED
@@ -17,6 +17,12 @@ module CEML
17
17
  INCIDENTS[id] ||= CEML::Incident.new to_bytecode(script), id if script
18
18
  raise "no incident #{id}" unless INCIDENTS[id]
19
19
  yield INCIDENTS[id], PLAYERS[id], metadata if block_given?
20
+
21
+ PLAYERS[id].select{ |p| p[:released] }.each do |p|
22
+ release p
23
+ ping_all p[:script_collection_id], p
24
+ end
25
+
20
26
  id
21
27
  end
22
28
  alias_method :start, :with_incident
@@ -48,15 +54,24 @@ module CEML
48
54
  SCRIPTS[script_collection_id].each{ |s| release script_collection_id, s.roles_to_cast, candidate }
49
55
  end
50
56
 
57
+ def release p
58
+ p[:tags] -= ['new']
59
+ if p[:released] =~ /^(\w+)=/
60
+ p[:tags].delete_if{ |t| t =~ /^#{$1}=/ }
61
+ end
62
+ p[:tags] += [p[:released]]
63
+ [:pc, :roles, :released].each{ |sym| p.delete(sym) }
64
+ (p[:matchables]||={}).update (p[:qs_answers]||{})
65
+ end
51
66
 
52
- def launch script_collection_id, roleset, *cast
67
+ def launch id, script_collection_id, roleset, *cast
53
68
  script = SCRIPTS[script_collection_id].select{ |s| s.roles_to_cast == roleset }.sort_by{ rand }.first
54
69
  unless script
55
70
  rolesets = SCRIPTS[script_collection_id].map(&:roles_to_cast)
56
71
  raise "matching roleset not found: #{roleset.inspect} in #{rolesets.inspect}"
57
72
  end
58
73
  log "launching #{script.bytecode.inspect} with cast #{cast.inspect}"
59
- push nil, script.bytecode, *cast
74
+ push id, script.bytecode, *cast
60
75
  end
61
76
 
62
77
 
@@ -69,29 +84,34 @@ module CEML
69
84
  return unless roleset.any?{ |r| r.fits? candidate }
70
85
  candidate[:ts] = CEML.clock
71
86
  already_launched_with = nil
87
+ run_after = []
72
88
 
73
89
  with_confluences script_collection_id, roleset do |confluences|
74
- live_with = confluences.select{ |c| c.live_with?(candidate) }
75
- if not live_with.empty?
76
- already_launched_with = live_with.first.incident_id
77
- live_with.each{ |c| c.rm candidate } if involvement != :sticky
78
- break if involvement != :released
79
- end
90
+ already_launched_with = nil
91
+ # live_with = confluences.select{ |c| c.live_with?(candidate) }
92
+ # if not live_with.empty?
93
+ # already_launched_with = live_with.first.incident_id
94
+ # live_with.each{ |c| c.rm candidate } if involvement != :sticky
95
+ # break if involvement != :released
96
+ # end
80
97
 
81
98
  locs = confluences.group_by{ |l| l.stage_with_candidate(candidate) }
82
99
  if locs[:joinable]
83
100
  log "joining..."
84
101
  first = locs[:joinable].shift
85
102
  first.push candidate unless first.incident_id == already_launched_with
86
- push first.incident_id, nil, candidate # JOIN THEM
103
+ # JOIN THEM
104
+ run_after << [:push, first.incident_id, nil, candidate]
87
105
 
88
106
  elsif locs[:launchable]
89
107
  log "launching..."
90
108
  first = locs[:launchable].shift
91
109
  first.push candidate
92
110
  cast = first.cast
93
- first.incident_id = launch script_collection_id, roleset, *cast
111
+ first.incident_id = gen_code
94
112
  (locs[:launchable] + (locs[:listable]||[])).each{ |l| l.rm *cast }
113
+ # LAUNCH
114
+ run_after << [:launch, first.incident_id, script_collection_id, roleset, *cast]
95
115
 
96
116
  elsif locs[:listable]
97
117
  log "listing..."
@@ -103,7 +123,8 @@ module CEML
103
123
  if c.stage_with_candidate(candidate) == :launchable
104
124
  log "start-launching..."
105
125
  c.push candidate
106
- c.incident_id = launch script_collection_id, roleset, candidate
126
+ c.incident_id = gen_code
127
+ run_after << [:launch, c.incident_id, script_collection_id, roleset, candidate]
107
128
  else
108
129
  c.push candidate
109
130
  end
@@ -112,10 +133,14 @@ module CEML
112
133
  confluences.delete_if(&:over?)
113
134
  end
114
135
 
115
- if already_launched_with and involvement == :sticky
116
- puts "PUSHING INSTEAD"
117
- push already_launched_with, nil, candidate
136
+ run_after.each do |cmd|
137
+ send(*cmd)
118
138
  end
139
+
140
+ # if already_launched_with and involvement == :sticky
141
+ # puts "PUSHING INSTEAD"
142
+ # push already_launched_with, nil, candidate
143
+ # end
119
144
  end
120
145
 
121
146
  def push incident_id, script, *updated_players
@@ -164,21 +189,5 @@ module CEML
164
189
  # def player_start(data, what)
165
190
  # puts "STARTED #{data[:player].inspect}"
166
191
  # end
167
-
168
- def player_released(data, tag)
169
- p = data[:player].dup
170
- p[:tags] -= ['new']
171
- if tag =~ /^(\w+)=/
172
- p[:tags].delete_if{ |t| t =~ /^#{$1}=/ }
173
- end
174
- p[:tags] += [tag]
175
- p.delete :pc
176
- p.delete :roles
177
- data[:player][:released] = true
178
- # data[:players].delete_if{ |pl| pl[:id] == p[:id] }
179
- puts "released: #{p.inspect} with #{tag}"
180
- # puts "remaining players: #{data[:players].inspect}"
181
- ping_all p[:script_collection_id], p, true
182
- end
183
192
  end
184
193
  end
data/lib/ceml/incident.rb CHANGED
@@ -28,22 +28,30 @@ module CEML
28
28
  def run(players, &blk)
29
29
  @players = players
30
30
  @callback = blk
31
- puts "playing with #{@players.map{|p|p[:id]}}"
32
- :loop while @players.any? do |thing|
33
- @this = thing
34
- next if thing[:released]
35
- puts "trying #{@this[:id]}"
36
- puts "not yet released"
37
- next unless instr = seq[pc]
38
- instr = instr.dup
39
- if rolematch(instr.shift)
40
- instr << role_info if instr.first == :start #tmp hack
41
- next unless send(*instr)
42
- cb(*instr)
31
+
32
+ loop do
33
+ players = @players.select{ |p| !p[:released] }
34
+ # puts "playing with #{players.map{|p|p[:id]}}"
35
+ advanced = false
36
+ players.each do |p|
37
+ @this = p
38
+ # puts "trying #{@this[:id]}"
39
+ next unless instr = seq[pc]
40
+ instr = instr.dup
41
+ if not rolematch(instr.shift)
42
+ this[:pc]+=1
43
+ advanced = true
44
+ else
45
+ instr << role_info if instr.first == :start #tmp hack
46
+ next unless send(*instr)
47
+ cb(*instr)
48
+ this[:pc]+=1
49
+ advanced = true
50
+ end
43
51
  end
44
- # next if @this[:released]
45
- this[:pc]+=1
52
+ break unless advanced
46
53
  end
54
+
47
55
  @callback = @players = nil
48
56
  end
49
57
 
@@ -171,6 +179,7 @@ module CEML
171
179
 
172
180
  def release x
173
181
  return true if x[:cond] and not expectation(*x[:cond])
182
+ this[:released] = x[:tag]
174
183
  cb :released, x[:tag]
175
184
  false
176
185
  end
data/lib/ceml/role.rb CHANGED
@@ -41,7 +41,10 @@ module CEML
41
41
  return true unless star
42
42
  c = criteria
43
43
  if c.matching
44
- return unless c.matching.all?{ |g| candidate[:matchables][g] == star[:matchables][g] }
44
+ return unless c.matching.all? do |g|
45
+ candidate[:matchables][g] && star[:matchables][g] &&
46
+ candidate[:matchables][g].downcase.strip == star[:matchables][g].downcase.strip
47
+ end
45
48
  end
46
49
  if c.radius
47
50
  c_ll = Geokit::LatLng(candidate[:lat], candidate[:lng])
data/test/test_release.rb CHANGED
@@ -44,40 +44,13 @@ await 1 new signup
44
44
  ask signup re first_name:
45
45
  Thanks for signing up for Infatuated!
46
46
  What's your first name?
47
- ask signup re couple:
48
- Do you have an Infatuated Match Card you want to use?
49
- (These are available at the Infatuated table on the first floor.)
50
- release signup as stage=couple if yes
51
- ask signup re tags:
52
- Who are you and who are you looking for tonight? (text back one: w4w, w4m, m4m, or m4w)
53
-
54
- await stage=couple player
55
- ask player re code:
47
+ ask signup re code:
56
48
  Type in your Infatuated Match Card code now.
57
- release player as stage=coded
58
-
59
- await 1 stage=coded alpha and 1 stage=coded beta with matching code
60
- release alpha as alpha
61
- release beta as beta
62
-
63
- await 1 w4w alpha and 1 w4w beta
64
- release alpha as alpha
65
- release beta as beta
66
-
67
- await 1 w4m alpha and 1 m4w beta
68
- release alpha as alpha
69
- release beta as beta
70
-
71
- await 1 m4m alpha and 1 m4m beta
72
- release alpha as alpha
73
- release beta as beta
74
-
75
- await 1 m4w alpha and 1 w4m beta
76
- release alpha as alpha
77
- release beta as beta
49
+ release signup as coded
78
50
 
79
- await 1 alpha alpha, 1 beta beta over 5 minutes
80
- tell both: Your date has started, |her.first_name|, |buddy.first_name|
51
+ await 1 coded alpha and 1 coded beta with matching code
52
+ tell alpha: You are alpha |her.first_name|, beta is |buddy.first_name|
53
+ tell beta: You are beta |her.first_name|, alpha is |buddy.first_name|
81
54
  XXXX
82
55
 
83
56
 
@@ -88,18 +61,17 @@ XXXX
88
61
  ping f, :id => 'Jon', :tags => ['new']
89
62
  asked 'Sara', /Thanks/
90
63
  says 'Sara', 'Sara'
91
- asked 'Sara', /Match Card/
92
- says 'Sara', 'y'
64
+
93
65
  asked 'Jon', /Thanks/
94
66
  says 'Jon', 'Jon'
67
+
68
+ asked 'Sara', /Match Card/
95
69
  asked 'Jon', /Match Card/
96
- says 'Jon', 'y'
97
- asked 'Sara', /code now/
98
70
  says 'Sara', 'xyzzy'
99
- asked 'Jon', /code now/
100
71
  says 'Jon', 'xyZZy '
101
- told 'Sara', /started, Sara, Jon/
102
- told 'Jon', /started, Jon, Sara/
72
+
73
+ told 'Sara', /alpha Sara, beta is Jon/
74
+ told 'Jon', /beta Jon, alpha is Sara/
103
75
  end
104
76
  end
105
77
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 4
9
- version: 0.7.4
8
+ - 5
9
+ version: 0.7.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Edelman