tyler-uppercut 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 0
2
+ patch: 1
3
3
  major: 0
4
4
  minor: 7
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'uppercut'
3
+ require 'yahoo-weather'
4
+ require 'feed_tools'
5
+
6
+ class PersonalAgent < Uppercut::Agent
7
+ def get_weather
8
+ @weather_client ||= YahooWeather::Client.new
9
+ @weather_client.lookup_location('94102') # lookup by zipcode
10
+ end
11
+
12
+ def get_news
13
+ FeedTools::Feed.open('feed://www.nytimes.com/services/xml/rss/nyt/HomePage.xml')
14
+ end
15
+
16
+ command 'weather' do |c,args|
17
+ weather = get_weather
18
+ c.send "#{weather.title}\n#{weather.condition.temp} degrees\n#{weather.condition.text}"
19
+ end
20
+
21
+ command 'forecast' do |c,args|
22
+ response = get_weather
23
+ msg = "#{response.forecasts[0].day} - #{response.forecasts[0].text}. "
24
+ msg << "High: #{response.forecasts[0].high} Low: #{response.forecasts[0].low}\n"
25
+ msg << "#{response.forecasts[1].day} - #{response.forecasts[1].text}. "
26
+ msg << "High: #{response.forecasts[1].high} Low: #{response.forecasts[1].low}\n"
27
+ c.send msg
28
+ end
29
+
30
+ command 'news' do |c,args|
31
+ msg = get_news.items[0,5].map { |item|
32
+ "#{item.title}\n#{item.link}"
33
+ }.join("\n\n")
34
+ c.send msg
35
+ end
36
+ end
37
+
38
+ if $0 == __FILE__
39
+ agent = PersonalAgent.new('name@domain.com/PersonalAgent','password')
40
+ agent.listen
41
+ sleep
42
+ end
@@ -16,10 +16,10 @@ class Uppercut
16
16
  # any captures in the pattern Regexp. (Does not apply to String
17
17
  # patterns).
18
18
  def command(pattern,&block)
19
- define_method(gensym) do |msg|
20
- return :no_match unless captures = matches?(pattern,msg.body)
21
- block[Conversation.new(msg.from,self),*captures]
22
- end
19
+ @@patterns ||= []
20
+ g = gensym
21
+ @@patterns << [pattern,g]
22
+ define_method(g, &block)
23
23
  end
24
24
 
25
25
  # Define a callback for specific presence events.
@@ -39,7 +39,7 @@ class Uppercut
39
39
  private
40
40
 
41
41
  def gensym
42
- '__uc' + (self.instance_methods.grep(/^__uc/).size).to_s.rjust(8,'0')
42
+ ('__uc' + (self.instance_methods.grep(/^__uc/).size).to_s.rjust(8,'0')).intern
43
43
  end
44
44
  end
45
45
 
@@ -182,7 +182,12 @@ class Uppercut
182
182
  block = @redirects[bare_from].respond_to?(:shift) && @redirects[bare_from].shift
183
183
  return block[msg.body] if block
184
184
 
185
- self.methods.grep(/^__uc/).sort.detect { |m| send(m,msg) != :no_match }
185
+ captures = nil
186
+ pair = @@patterns.detect { |pattern,method| captures = matches?(pattern,msg.body) }
187
+ if pair
188
+ pattern, method = pair if pair
189
+ send method, Conversation.new(msg.from,self), captures
190
+ end
186
191
  end
187
192
 
188
193
  def dispatch_presence(type, presence)
data/spec/spec_helper.rb CHANGED
@@ -12,22 +12,22 @@ require 'uppercut'
12
12
  require 'jabber_stub'
13
13
 
14
14
  class TestAgent < Uppercut::Agent
15
- command 'hi' do |c|
15
+ command 'hi' do |c,args|
16
16
  c.instance_eval { @base.instance_eval { @called_hi = true } }
17
17
  c.send 'called hi'
18
18
  end
19
19
 
20
- command /^hi/ do |c|
20
+ command /^hi/ do |c,args|
21
21
  c.instance_eval { @base.instance_eval { @called_hi_regex = true } }
22
22
  c.send 'called high regex'
23
23
  end
24
24
 
25
- command /(good)?bye/ do |c,good|
25
+ command /(good)?bye/ do |c,args|
26
26
  @called_goodbye = true
27
- c.send good ? "Good bye to you as well!" : "Rot!"
27
+ c.send args.first ? "Good bye to you as well!" : "Rot!"
28
28
  end
29
29
 
30
- command 'wait' do |c|
30
+ command 'wait' do |c,args|
31
31
  @called_wait = true
32
32
  c.send 'Waiting...'
33
33
  c.wait_for do |reply|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tyler-uppercut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler McMullen
@@ -45,6 +45,7 @@ files:
45
45
  - spec/notifier_spec.rb
46
46
  - spec/spec_helper.rb
47
47
  - examples/basic_agent.rb
48
+ - examples/personal.rb
48
49
  has_rdoc: false
49
50
  homepage: http://github.com/tyler/uppercut
50
51
  post_install_message: