tjplurk 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cd527e15ff2998cc0897451a689ba1d17af2dae
4
- data.tar.gz: 3068e2f15710797cbb42eac67b4772077c1f7da8
3
+ metadata.gz: 0e1dcd345564228d02697e72691d1f52400c2f49
4
+ data.tar.gz: 8b1fc2bbd60aabb7d9491a2dc721acce3a9d420a
5
5
  SHA512:
6
- metadata.gz: 0aa55b54ea3c90f442255effca2bd515b2ed08b136c3b59ca54853a9befed3261d134f657f304095593a0a4ca73e4dea4d16792267461e71e73b71a6e4ebf53a
7
- data.tar.gz: 6f8fe3cf757e4a79929b1b24d71ac3e439e68b91593ecd75b10a7f87f3d4771f27fdf96fd7b267b30baefe186c0e469106f48a9de484ec400cb3ea72831c057f
6
+ metadata.gz: f6e8f8730155a3dc73ca6fa5fd180ca4f2485e37ff2112dc64055418b429eb870984e7ee5d7863a4e4b98300b1f6d5ff8db15addb5e7e328151f4dad2c408395
7
+ data.tar.gz: 028ed05cc9a3ef8aec4491f4d6aaa54699ff05b64aab43739837102a83acf8547da89969c8a44d377b865aab0694555a01a790db204cb11127366f99dda46eb1
@@ -0,0 +1,10 @@
1
+ module Tjplurk
2
+ class Robot
3
+ class Response
4
+ attr_accessor :topic, :content
5
+ def initialize **params
6
+ params.each{|key, value| send("#{key}=", value)}
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ require 'tjplurk/robot/response'
2
+ require 'yaml'
3
+
4
+ module Tjplurk
5
+ class Robot
6
+ class Topic
7
+ attr_accessor :name, :pattern, :responses
8
+ class << self
9
+ def load yaml
10
+ YAML.load(yaml).map do |attributes|
11
+ topic = self.new name: attributes['name'], pattern: attributes['pattern']
12
+ topic.responses = attributes['responses'].map{|res| Response.new(topic: topic, content: res)}
13
+ topic
14
+ end
15
+ end
16
+ end
17
+
18
+ def initialize(**params)
19
+ params.each{|key, value| send("#{key}=", value)}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Tjplurk
2
+ class Robot
3
+ def initialize topics
4
+ @topics = topics
5
+ end
6
+
7
+ def respond s
8
+ if matched = @topics.select{|category| Regexp.new(category.pattern).match(s) }.sample
9
+ matched.responses.sample.content
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Tjplurk
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
data/lib/tjplurk.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'tjplurk/api'
2
-
3
2
  module Tjplurk
4
3
  OAUTH_OPTIONS = {
5
4
  site: 'http://www.plurk.com',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tjplurk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Jian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -77,6 +77,9 @@ files:
77
77
  - lib/tjplurk.rb
78
78
  - lib/tjplurk/api.rb
79
79
  - lib/tjplurk/cli.rb
80
+ - lib/tjplurk/robot.rb
81
+ - lib/tjplurk/robot/response.rb
82
+ - lib/tjplurk/robot/topic.rb
80
83
  - lib/tjplurk/version.rb
81
84
  homepage: https://github.com/tonytonyjan/tjplurk
82
85
  licenses: