ruboty-attend 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52a4cb6e216057c6498a68d0808e7bc58368a210
4
+ data.tar.gz: 011328af928502c0676d537d88e12260ecdef58f
5
+ SHA512:
6
+ metadata.gz: 459127a04c49eb3a0ee21d867b9197f31f35916c0d9541050af9e13ef3eb862b0cfcd6da61e528f73fb6922eda29983080fa74bc5c900c23c5ac45d51360e005
7
+ data.tar.gz: 113a13e95165f542888a692d0d1922f98d01ba38eba0f821b50c4d04f9230fb3f3957610e8e234cb9d69066325e1ece20e52487637202e8ae1de4f60ffaf1233
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-attend.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 everysick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Ruboty::Attend
2
+
3
+ Management attendance.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-attend'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruboty-attend
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ ruboty /create_attendance\s?(?<desc>.+?)\z/ - create new attendance
25
+ ruboty /close_attendance\s?(?<ch>(\d)+?)\z/ - close attendance
26
+ ruboty /absent\s?(?<ch>(\d)+?)\z/ - absent target channel event
27
+ ruboty /attend\s?(?<ch>(\d)+?)\z/ - attend target channel event
28
+ ruboty /all_attendance\z/ - show all attendance
29
+ ruboty /attend_status\s?(?<ch>(\d)+?)\z/ - get state of channel
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Everysick/ruboty-attend. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "ruboty/attend/version"
2
+ require "ruboty/handlers/attendance"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Attend
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,148 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Attendance < Base
4
+ NAMESPACE = 'ruboty-attend'
5
+ ROLE = { attend: 'Attend', absent: 'Absent' }
6
+
7
+ on(
8
+ /create_attendance\s?(?<desc>.+?)\z/,
9
+ name: 'create_attendance',
10
+ description: 'create new attendance'
11
+ )
12
+
13
+ on(
14
+ /attend_status\s?(?<ch>(\d)+?)\z/,
15
+ name: 'attend_status',
16
+ description: 'get state of channel'
17
+ )
18
+
19
+ on(
20
+ /close_attendance\s?(?<ch>(\d)+?)\z/,
21
+ name: 'close_attendance',
22
+ description: 'close attendance'
23
+ )
24
+
25
+ on(
26
+ /all_attendance\z/,
27
+ name: "all_attendance",
28
+ description: 'show all attendance'
29
+ )
30
+
31
+ on(
32
+ /attend\s?(?<ch>(\d)+?)\z/,
33
+ name: 'attend_user',
34
+ description: 'attend target channel event'
35
+ )
36
+
37
+ on(
38
+ /absent\s?(?<ch>(\d)+?)\z/,
39
+ name: 'absent_user',
40
+ description: 'absent target channel event'
41
+ )
42
+
43
+ def create_attendance(message)
44
+ begin
45
+ new_ch_num = create_new_chx
46
+ attend_table[new_ch_num] = {}
47
+ attend_ch[new_ch_num] = message[:desc]
48
+ message.reply("Create new channel event!\n Ch.No. -> #{new_ch_num}, Detail -> #{attend_ch[new_ch_num]}")
49
+ rescue => e
50
+ message.reply(e.message)
51
+ end
52
+ end
53
+
54
+ def attend_status(message)
55
+ begin
56
+ current_ch = message[:ch].to_i
57
+ message.reply(current_message(current_ch))
58
+ rescue => e
59
+ message.reply(e.message)
60
+ end
61
+ end
62
+
63
+ def close_attendance(message)
64
+ begin
65
+ current_ch = message[:ch].to_i
66
+ result_message = current_message(current_ch)
67
+ attend_table.delete(current_ch)
68
+ attend_ch.delete(current_ch)
69
+ message.reply(result_message)
70
+ rescue => e
71
+ message.reply(e.message)
72
+ end
73
+ end
74
+
75
+ def all_attendance(message)
76
+ begin
77
+ result_message = "All channel event is here\n"
78
+ attend_ch.keys.each do |ch_num|
79
+ result_message += current_message(ch_num)
80
+ end
81
+ message.reply(result_message)
82
+ rescue => e
83
+ message.reply(e.message)
84
+ end
85
+ end
86
+
87
+ def attend_user(message)
88
+ begin
89
+ message.reply(divide_user(:attend, message))
90
+ rescue => e
91
+ message.reply(e.message)
92
+ end
93
+ end
94
+
95
+ def absent_user(message)
96
+ begin
97
+ message.reply(divide_user(:absent, message))
98
+ rescue => e
99
+ message.reply(e.message)
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ def divide_user(state, message)
106
+ current_ch = message[:ch].to_i
107
+
108
+ if ch_exist?(current_ch)
109
+ return "Ch.#{current_ch} does not exist."
110
+ end
111
+
112
+ attend_table[current_ch].merge!({ message.from_name => state })
113
+ "#{attend_ch[current_ch]}に#{ROLE[state]}っ!"
114
+ end
115
+
116
+ def ch_exist?(ch_num)
117
+ attend_table[ch_num].nil?
118
+ end
119
+
120
+ def current_message(current_ch)
121
+ if ch_exist?(current_ch)
122
+ return "Ch.#{current_ch} does not exist."
123
+ end
124
+
125
+ attend_counter = 0
126
+ ret_message = "[Ch.#{current_ch}, #{attend_ch[current_ch]}]\n"
127
+ attend_table[current_ch].each do |key, val|
128
+ ret_message += "#{key.to_s}: #{ROLE[val]}\n"
129
+ attend_counter += 1 if val == :attend
130
+ end
131
+
132
+ ret_message + "num of attend user: #{attend_counter}\n"
133
+ end
134
+
135
+ def attend_table
136
+ robot.brain.data[NAMESPACE + "_table"] ||= {}
137
+ end
138
+
139
+ def attend_ch
140
+ robot.brain.data[NAMESPACE + "_ch"] ||= {}
141
+ end
142
+
143
+ def create_new_ch
144
+ (1..100).to_a.select {|num| !attend_ch.keys.include?(num)}.first
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/attend/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-attend"
8
+ spec.version = Ruboty::Attend::VERSION
9
+ spec.authors = ["everysick"]
10
+ spec.email = ["s.wakeup31@gmail.com"]
11
+
12
+ spec.summary = "Management attendance."
13
+ spec.homepage = "http://github.com/Everysick/ruboty-attend"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "ruboty"
25
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-attend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - everysick
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruboty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - s.wakeup31@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/attend.rb
82
+ - lib/ruboty/attend/version.rb
83
+ - lib/ruboty/handlers/attendance.rb
84
+ - ruboty-attend.gemspec
85
+ homepage: http://github.com/Everysick/ruboty-attend
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.5.1
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Management attendance.
109
+ test_files: []