ruboty-rotation 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Rakefile +1 -0
- data/lib/ruboty/handlers/rotation.rb +103 -0
- data/lib/ruboty/rotation/version.rb +5 -0
- data/lib/ruboty/rotation.rb +3 -0
- data/ruboty-rotation.gemspec +22 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eea9402492ac97717699361961ab20b74be1ddc0
|
4
|
+
data.tar.gz: 9919bb3d668b2db3558aec800a12d3f69a8540f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fc7ab1a7616d967e29a38c82c3de900d1a221afc177cfb18816a66700cb46b8d6f84c8fde54334689a8492e49fe0a921571179f0ac75b7b9632b6b2f2af7445
|
7
|
+
data.tar.gz: bea38b3e31d9d40bb9370c3556cf9bf7a7acb7b42ae07a55866122becd4d32bc1014d52828166cda98bb6152f5b5d2d881a1da99f173a78083f14eb716cfde6d
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Handlers
|
3
|
+
class Rotation < Base
|
4
|
+
NAMESPACE = "rotation"
|
5
|
+
|
6
|
+
on(/rotation items add (?<item>.+)/, name: "add_item", description: "Add item")
|
7
|
+
on(/rotation items delete (?<item>.+)/, name: "delete_item", description: "Delete item")
|
8
|
+
on(/rotation items\z/, name: "list_items", description: "List items")
|
9
|
+
on(/rotation next\z/, name: "move_to_next", description: "Rotate to next")
|
10
|
+
on(/rotation prev\z/, name: "move_to_prev", description: "Rotate to prev")
|
11
|
+
on(/rotation current\z/, name: "current", description: "Show current")
|
12
|
+
|
13
|
+
attr_writer :items
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super
|
17
|
+
set_current
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_item(message)
|
21
|
+
item = message[:item]
|
22
|
+
|
23
|
+
if items.include?(item)
|
24
|
+
message.reply("Item #{item} already exist")
|
25
|
+
else
|
26
|
+
items << item
|
27
|
+
message.reply("Item #{item} added")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete_item(message)
|
32
|
+
item = message[:item]
|
33
|
+
|
34
|
+
if items.include?(item)
|
35
|
+
items.delete(item)
|
36
|
+
message.reply("Item #{item} deleted")
|
37
|
+
else
|
38
|
+
message.reply("Item #{item} does not exist")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def list_items(message)
|
43
|
+
message.reply(items.join(","), code: true)
|
44
|
+
end
|
45
|
+
|
46
|
+
def move_to_next(message)
|
47
|
+
index = current_index + 1
|
48
|
+
|
49
|
+
if index >= items.size
|
50
|
+
set_index(0)
|
51
|
+
else
|
52
|
+
set_index(index)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def move_to_prev(message)
|
57
|
+
index = current_index - 1
|
58
|
+
|
59
|
+
if index < 0
|
60
|
+
set_index(items.size - 1)
|
61
|
+
else
|
62
|
+
set_index(index)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def current(message)
|
67
|
+
message.reply([
|
68
|
+
ENV['ROTATION_CURRENT_PREFIX'],
|
69
|
+
current_item,
|
70
|
+
ENV['ROTATION_CURRENT_SUFFIX']
|
71
|
+
].compact.join(""))
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def current_item
|
77
|
+
items[current_index]
|
78
|
+
end
|
79
|
+
|
80
|
+
def current_index
|
81
|
+
robot.brain.data[NAMESPACE][:current_index]
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_index(index)
|
85
|
+
robot.brain.data[NAMESPACE][:current_index] = index
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_current
|
89
|
+
setup_brain
|
90
|
+
robot.brain.data[NAMESPACE][:current_index] ||= 0
|
91
|
+
end
|
92
|
+
|
93
|
+
def items
|
94
|
+
setup_brain
|
95
|
+
robot.brain.data[NAMESPACE][:items] ||= []
|
96
|
+
end
|
97
|
+
|
98
|
+
def setup_brain
|
99
|
+
robot.brain.data[NAMESPACE] ||= {}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "ruboty/rotation/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ruboty-rotation"
|
7
|
+
spec.version = Ruboty::Rotation::VERSION
|
8
|
+
spec.authors = ["Jun OHWADA"]
|
9
|
+
spec.email = ["june29.jp@gmail.com"]
|
10
|
+
spec.summary = "Rotation management system for Ruboty"
|
11
|
+
spec.homepage = "https://github.com/june29/ruboty-rotation"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "ruboty", ">= 0.2.0"
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-rotation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jun OHWADA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- june29.jp@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Rakefile
|
64
|
+
- lib/ruboty/handlers/rotation.rb
|
65
|
+
- lib/ruboty/rotation.rb
|
66
|
+
- lib/ruboty/rotation/version.rb
|
67
|
+
- ruboty-rotation.gemspec
|
68
|
+
homepage: https://github.com/june29/ruboty-rotation
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.4.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Rotation management system for Ruboty
|
92
|
+
test_files: []
|