ruboty-gominohi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.gominohi.yml.sample +15 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +15 -0
- data/bin/console +7 -0
- data/lib/ruboty/gominohi.rb +7 -0
- data/lib/ruboty/gominohi/notification.rb +46 -0
- data/lib/ruboty/gominohi/version.rb +5 -0
- data/lib/ruboty/gominohi/yaml.rb +55 -0
- data/lib/ruboty/handlers/gominohi.rb +15 -0
- data/ruboty-gominohi.gemspec +28 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 151be6af0d95fa40fb2b2a2186806a6f4069762f
|
4
|
+
data.tar.gz: 6aa7412738adfa83977ad9c23874c10f50a67f12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dff0b41cc2b1c0d87ba54bdbeac58ad5e2e44c63bbbe995645bead12765e6c92e5ad443d35e06d2044ef1988a9374433150970da09b4727e05db1f87dc6b22ae
|
7
|
+
data.tar.gz: de87714dccd4ca1e4eb0ef343d773fa53cf2fb967286cd5d782e3adc9e579c0f040965c6aaddb83226fcd9f9f222ffef747610b8aa8ec283c60e9f16151adcaa
|
data/.gitignore
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
version: '0.1.0'
|
2
|
+
garbage_collectors:
|
3
|
+
- foo
|
4
|
+
- bar
|
5
|
+
garbage_collection_days:
|
6
|
+
- name: '可燃ごみ'
|
7
|
+
wday: [3, 6]
|
8
|
+
emoticon: ':fire:'
|
9
|
+
- name: '不燃ごみ'
|
10
|
+
wday: [4]
|
11
|
+
position: [2, 4]
|
12
|
+
emoticon: ':put_litter_in_its_place:'
|
13
|
+
- name: '資源'
|
14
|
+
wday: [5]
|
15
|
+
emoticon: ':recycle:'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 SHIOYA, Hiromu
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Ruboty::Gominohi
|
2
|
+
|
3
|
+
[ruboty](https://github.com/r7kamura/ruboty) plugin that tells garbage collection day
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
- put `.gominohi.yml` on...
|
8
|
+
- root directory of this gem
|
9
|
+
- root directory of your ruboty
|
10
|
+
- see bundled `.gominohi.yml.sample`
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
- `ruboty gominohi`
|
15
|
+
- notify garbage collection of current day
|
16
|
+
- better to use with `ruboty-cron`
|
17
|
+
- e.g) `ruboty add job "30 7 * * *" ruboty gominohi`
|
18
|
+
|
19
|
+
### `.gominohi.yml`
|
20
|
+
|
21
|
+
- `version`
|
22
|
+
- specify version of this file
|
23
|
+
- compared between app's version
|
24
|
+
- must be same major and minor version (patch version is ignored)
|
25
|
+
- `garbage_collectiors`
|
26
|
+
- specify member names to send notification (optional)
|
27
|
+
- `garbage_collection_days`
|
28
|
+
- specify days of collect some garbages
|
29
|
+
- `wday` : array of wday (1 : Monday)
|
30
|
+
- `emoticon` : used as prefix
|
31
|
+
- `position` : if specified, show only `n`th wday
|
32
|
+
- e.g `wday: [4] position: [2, 4]` : notifies on 2nd and 4th Thursday
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
task default: :test
|
5
|
+
|
6
|
+
desc 'Run test_unit based test'
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
unless File.exists?('./.gominohi.yml')
|
9
|
+
FileUtils.copy('./.gominohi.yml.sample', './.gominohi.yml')
|
10
|
+
end
|
11
|
+
|
12
|
+
t.libs << 'test'
|
13
|
+
t.test_files = Dir['test/**/test_*.rb']
|
14
|
+
t.verbose = true
|
15
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Gominohi
|
3
|
+
class Notification
|
4
|
+
attr_reader :date
|
5
|
+
|
6
|
+
def initialize(date = Date.today)
|
7
|
+
@date = date
|
8
|
+
@yaml = YAML.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def search_garbage_collection_days
|
12
|
+
@yaml.data[:garbage_collection_days].each_with_object([]) do |day, result|
|
13
|
+
next unless day[:wday].include?(@date.wday)
|
14
|
+
if !day.key?(:position) || day[:position].include?(@date.wday_position)
|
15
|
+
result.push(day)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def message
|
21
|
+
days = search_garbage_collection_days
|
22
|
+
unless days.empty?
|
23
|
+
result = days.map { |day| format(day) }
|
24
|
+
str = if days.count > 1
|
25
|
+
s = result.map { |r| "- #{r}" }.join("\n")
|
26
|
+
"\n#{s}\n"
|
27
|
+
else
|
28
|
+
" #{result.first} "
|
29
|
+
end
|
30
|
+
|
31
|
+
collectors = if @yaml.data[:garbage_collectors].empty?
|
32
|
+
''
|
33
|
+
else
|
34
|
+
@yaml.data[:garbage_collectors].map { |name| name.start_with?('@') ? name : "@#{name}" }.join(' ') + ' '
|
35
|
+
end
|
36
|
+
|
37
|
+
"#{collectors}#{@date.month}月#{@date.day}日(#{@date.wday_name})のごみ収集は#{str}です。"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def format(garbage_collection_day)
|
42
|
+
"#{garbage_collection_day[:emoticon]} *#{garbage_collection_day[:name]}*"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module Gominohi
|
5
|
+
class YAML
|
6
|
+
YAML_DIRS = [
|
7
|
+
Dir.pwd,
|
8
|
+
File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', '..')
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
YAML_FILE = '.gominohi.yml'.freeze
|
12
|
+
|
13
|
+
attr_reader :data
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
YAML_DIRS.each do |dir|
|
17
|
+
filename = File.join(dir, YAML_FILE)
|
18
|
+
if File.exists?(filename)
|
19
|
+
@data = deep_symbolize_keys(::YAML.load(File.read(filename)))
|
20
|
+
break
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
raise "#{YAML_FILE} is not found" if @data.nil?
|
25
|
+
|
26
|
+
yaml_version = parse_and_truncate_patch_version(@data[:version])
|
27
|
+
gominohi_version = parse_and_truncate_patch_version(::Ruboty::Gominohi::VERSION)
|
28
|
+
raise 'version of `.gominohi.yml` is invalid' unless yaml_version == gominohi_version
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def parse_and_truncate_patch_version(version_string)
|
34
|
+
version_ints = version_string.split('.').map(&:to_i).slice(0..1)
|
35
|
+
end
|
36
|
+
|
37
|
+
def symbolize_keys(hash)
|
38
|
+
hash.each_with_object({}) { |(k, v), result| result[k.to_sym] = v }
|
39
|
+
end
|
40
|
+
|
41
|
+
def deep_symbolize_keys(obj)
|
42
|
+
obj.to_hash.keys.each do |key|
|
43
|
+
case (v = obj.delete(key))
|
44
|
+
when Hash
|
45
|
+
v = symbolize_keys(v)
|
46
|
+
when Array
|
47
|
+
v = v.map{ |x| (symbolize_keys(x) rescue x) }
|
48
|
+
end
|
49
|
+
obj[(key.to_sym rescue key) || key] = v
|
50
|
+
end
|
51
|
+
obj
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Handlers
|
3
|
+
class Gominohi < Base
|
4
|
+
on(/gominohi(?<date>\Z|\s+.+)/, name: 'gominohi', description: 'tell what kind of garbage could be collected today.')
|
5
|
+
|
6
|
+
def gominohi(message)
|
7
|
+
date = Date.easy_parse(message[:date].strip)
|
8
|
+
notification = ::Ruboty::Gominohi::Notification.new(date)
|
9
|
+
str = notification.message
|
10
|
+
|
11
|
+
message.reply(str) unless str.nil?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'ruboty/gominohi/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ruboty-gominohi'
|
7
|
+
spec.version = Ruboty::Gominohi::VERSION
|
8
|
+
spec.authors = ['SHIOYA, Hiromu']
|
9
|
+
spec.email = ['kwappa.856@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Ruboty plugin to tell garbage collection day'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/kwappa/ruboty-gominohi'
|
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_dependency 'ruboty'
|
22
|
+
spec.add_dependency 'date_misc'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
spec.add_development_dependency 'test-unit'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-gominohi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SHIOYA, Hiromu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-25 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: date_misc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Ruboty plugin to tell garbage collection day
|
98
|
+
email:
|
99
|
+
- kwappa.856@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".gominohi.yml.sample"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- lib/ruboty/gominohi.rb
|
113
|
+
- lib/ruboty/gominohi/notification.rb
|
114
|
+
- lib/ruboty/gominohi/version.rb
|
115
|
+
- lib/ruboty/gominohi/yaml.rb
|
116
|
+
- lib/ruboty/handlers/gominohi.rb
|
117
|
+
- ruboty-gominohi.gemspec
|
118
|
+
homepage: https://github.com/kwappa/ruboty-gominohi
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.5.1
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Ruboty plugin to tell garbage collection day
|
142
|
+
test_files: []
|