ssc.bot 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ssc.bot/util.rb CHANGED
@@ -1,41 +1,28 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of SSC.Bot.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # SSC.Bot is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # SSC.Bot is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
24
12
  require 'rbconfig'
25
13
 
26
-
27
14
  module SSCBot
28
15
  ###
29
16
  # Your typical utility methods that
30
17
  # should be moved into a separate Gem one day...
31
- #
32
- # @author Jonathan Bradley Whited (@esotericpig)
18
+ #
19
+ # @author Jonathan Bradley Whited
33
20
  # @since 0.1.0
34
21
  ###
35
22
  module Util
36
23
  def self.os(host_os=RbConfig::CONFIG['host_os'])
37
24
  os = :unknown
38
-
25
+
39
26
  case host_os
40
27
  when /darwin/i
41
28
  os = :macos
@@ -50,12 +37,11 @@ module SSCBot
50
37
  os = :windows
51
38
  end
52
39
  end
53
-
40
+
54
41
  return os
55
42
  end
56
-
57
- OS = os()
58
-
43
+ OS = os
44
+
59
45
  def self.quote_str_or_regex(value)
60
46
  if value.respond_to?(:source)
61
47
  return value.source.gsub(' ','\\ ') # For //x
@@ -63,27 +49,47 @@ module SSCBot
63
49
  return Regexp.quote(value)
64
50
  end
65
51
  end
66
-
52
+
53
+ def self.ruby_engine
54
+ engines = [
55
+ defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : nil,
56
+ RbConfig::CONFIG['ruby_install_name'],
57
+ RbConfig::CONFIG['rubyw_install_name'],
58
+ RbConfig::CONFIG['RUBY_INSTALL_NAME'],
59
+ RbConfig::CONFIG['RUBYW_INSTALL_NAME'],
60
+ RbConfig.ruby,
61
+ ].join('|').downcase
62
+
63
+ if engines.include?('jruby')
64
+ return :jruby
65
+ elsif engines.include?('truffleruby')
66
+ return :truffleruby
67
+ end
68
+
69
+ return :ruby
70
+ end
71
+ RUBY_ENGINE = ruby_engine
72
+
67
73
  # Universally, is +str+ empty after stripping or +nil+?
68
74
  def self.u_blank?(str)
69
- return str.nil?() || u_strip(str).empty?()
75
+ return str.nil? || str.empty? || u_strip(str).empty?
70
76
  end
71
-
77
+
72
78
  # Universally, left strip +str+'s leading (head) space.
73
79
  def self.u_lstrip(str)
74
- return nil if str.nil?()
80
+ return nil if str.nil?
75
81
  return str.gsub(/\A[[:space:]]+/,'')
76
82
  end
77
-
83
+
78
84
  # Universally, right strip +str+'s trailing (tail) space.
79
85
  def self.u_rstrip(str)
80
- return nil if str.nil?()
86
+ return nil if str.nil?
81
87
  return str.gsub(/[[:space:]]+\z/,'')
82
88
  end
83
-
89
+
84
90
  # Universally, strip +str+'s space.
85
91
  def self.u_strip(str)
86
- return nil if str.nil?()
92
+ return nil if str.nil?
87
93
  return str.gsub(/\A[[:space:]]+|[[:space:]]+\z/,'')
88
94
  end
89
95
  end
@@ -1,26 +1,14 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of SSC.Bot.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # SSC.Bot is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # SSC.Bot is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
24
12
  module SSCBot
25
- VERSION = '0.1.1'
13
+ VERSION = '0.2.0'
26
14
  end
data/ssc.bot.gemspec CHANGED
@@ -1,68 +1,45 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- #--
5
- # This file is part of SSC.Bot.
6
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
- #
8
- # SSC.Bot is free software: you can redistribute it and/or modify
9
- # it under the terms of the GNU Lesser General Public License as published by
10
- # the Free Software Foundation, either version 3 of the License, or
11
- # (at your option) any later version.
12
- #
13
- # SSC.Bot is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU Lesser General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU Lesser General Public License
19
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
20
- #++
21
4
 
5
+ require_relative 'lib/ssc.bot/version'
22
6
 
23
- lib = File.expand_path(File.join('..','lib'),__FILE__)
24
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
25
-
26
- require 'ssc.bot/version'
27
-
28
-
29
- Gem::Specification.new() do |spec|
7
+ Gem::Specification.new do |spec|
30
8
  spec.name = 'ssc.bot'
31
9
  spec.version = SSCBot::VERSION
32
- spec.authors = ['Jonathan Bradley Whited (@esotericpig)']
33
- spec.email = ['bradley@esotericpig.com']
10
+ spec.authors = ['Jonathan Bradley Whited']
11
+ spec.email = ['code@esotericpig.com']
34
12
  spec.licenses = ['LGPL-3.0-or-later']
35
13
  spec.homepage = 'https://github.com/esotericpig/ssc.bot'
36
14
  spec.summary = 'Simple Subspace Continuum Bot library.'
37
15
  spec.description = spec.summary
38
-
16
+
39
17
  spec.metadata = {
40
- 'bug_tracker_uri' => 'https://github.com/esotericpig/ssc.bot/issues',
41
- 'changelog_uri' => 'https://github.com/esotericpig/ssc.bot/blob/master/CHANGELOG.md',
42
18
  'homepage_uri' => 'https://github.com/esotericpig/ssc.bot',
43
19
  'source_code_uri' => 'https://github.com/esotericpig/ssc.bot',
20
+ 'bug_tracker_uri' => 'https://github.com/esotericpig/ssc.bot/issues',
21
+ 'changelog_uri' => 'https://github.com/esotericpig/ssc.bot/blob/master/CHANGELOG.md',
44
22
  }
45
-
46
- spec.require_paths = ['lib']
47
- spec.bindir = 'bin'
48
-
23
+
24
+ spec.required_ruby_version = '>= 2.5'
25
+ spec.require_paths = ['lib']
26
+ spec.bindir = 'bin'
27
+
49
28
  spec.files = [
50
29
  Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{erb,rb}')),
51
30
  Dir.glob(File.join(spec.bindir,'*')),
52
31
  Dir.glob(File.join('{test,yard}','**','*.{erb,rb}')),
53
- %W( Gemfile #{spec.name}.gemspec Rakefile ),
54
- %w( CHANGELOG.md LICENSE.txt README.md ),
55
- ].flatten()
56
-
57
- spec.required_ruby_version = '>= 2.5'
58
-
59
- spec.add_runtime_dependency 'attr_bool','~> 0.1' # attr_accessor?/reader?
60
-
61
- spec.add_development_dependency 'bundler' ,'~> 2.1'
32
+ %W[ Gemfile #{spec.name}.gemspec Rakefile .yardopts ],
33
+ %w[ CHANGELOG.md LICENSE.txt README.md ],
34
+ ].flatten
35
+
36
+ spec.add_runtime_dependency 'attr_bool','~> 0.2' # attr_accessor?/reader?
37
+
38
+ spec.add_development_dependency 'bundler' ,'~> 2.2'
62
39
  spec.add_development_dependency 'minitest' ,'~> 5.14'
63
40
  spec.add_development_dependency 'rake' ,'~> 13.0'
64
- spec.add_development_dependency 'rdoc' ,'~> 6.2' # YARDoc RDoc (*.rb)
41
+ spec.add_development_dependency 'rdoc' ,'~> 6.3' # YARDoc RDoc (*.rb)
65
42
  spec.add_development_dependency 'redcarpet' ,'~> 3.5' # YARDoc Markdown (*.md)
66
- spec.add_development_dependency 'yard' ,'~> 0.9' # Documentation
43
+ spec.add_development_dependency 'yard' ,'~> 0.9' # Doc
67
44
  spec.add_development_dependency 'yard_ghurt','~> 1.2' # YARDoc GitHub Rake tasks
68
45
  end
data/test/test_helper.rb CHANGED
@@ -1,28 +1,12 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: UTF-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  #--
6
5
  # This file is part of SSC.Bot.
7
- # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
- #
9
- # SSC.Bot is free software: you can redistribute it and/or modify
10
- # it under the terms of the GNU Lesser General Public License as published by
11
- # the Free Software Foundation, either version 3 of the License, or
12
- # (at your option) any later version.
13
- #
14
- # SSC.Bot is distributed in the hope that it will be useful,
15
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- # GNU Lesser General Public License for more details.
18
- #
19
- # You should have received a copy of the GNU Lesser General Public License
20
- # along with SSC.Bot. If not, see <https://www.gnu.org/licenses/>.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
21
9
  #++
22
10
 
23
11
 
24
12
  require 'minitest/autorun'
25
-
26
-
27
- class TestHelper < Minitest::Test
28
- end
data/test/util_test.rb ADDED
@@ -0,0 +1,93 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ #--
5
+ # This file is part of SSC.Bot.
6
+ # Copyright (c) 2020-2021 Jonathan Bradley Whited
7
+ #
8
+ # SPDX-License-Identifier: LGPL-3.0-or-later
9
+ #++
10
+
11
+
12
+ require 'test_helper'
13
+
14
+ require 'ssc.bot/util'
15
+
16
+ describe SSCBot::Util do
17
+ let(:util) { SSCBot::Util }
18
+
19
+ let(:spaces) { " \r\n\t " }
20
+ let(:spaces_x) { "#{spaces}x#{spaces}" }
21
+
22
+ before do
23
+ end
24
+
25
+ after do
26
+ end
27
+
28
+ describe '.os()' do
29
+ it 'should match the constant' do
30
+ expect(util::OS).must_equal util.os
31
+ end
32
+
33
+ it 'should match macOS' do
34
+ expect(util.os('w/e Darwin w/e')).must_equal :macos
35
+ end
36
+
37
+ it 'should match Linux' do
38
+ expect(util.os('w/e Linux w/e')).must_equal :linux
39
+ end
40
+
41
+ it 'should match Windows' do
42
+ expect(util.os('w/e Windows w/e')).must_equal :windows
43
+ end
44
+ end
45
+
46
+ describe '.u_blank?()' do
47
+ it 'should match if nil' do
48
+ expect(util.u_blank?(nil)).must_equal true
49
+ end
50
+
51
+ it 'should match if empty' do
52
+ expect(util.u_blank?('')).must_equal true
53
+ end
54
+
55
+ it 'should strip spaces' do
56
+ expect(util.u_blank?(spaces)).must_equal true
57
+ end
58
+
59
+ it 'should not match if not empty' do
60
+ expect(util.u_blank?(' x ')).must_equal false
61
+ end
62
+ end
63
+
64
+ describe '.u_lstrip()' do
65
+ it 'should allow nil' do
66
+ expect(util.u_lstrip(nil)).must_be_nil
67
+ end
68
+
69
+ it 'should strip left/leading spaces' do
70
+ expect(util.u_lstrip(spaces_x)).must_equal "x#{spaces}"
71
+ end
72
+ end
73
+
74
+ describe '.u_rstrip()' do
75
+ it 'should allow nil' do
76
+ expect(util.u_rstrip(nil)).must_be_nil
77
+ end
78
+
79
+ it 'should strip right/trailing spaces' do
80
+ expect(util.u_rstrip(spaces_x)).must_equal "#{spaces}x"
81
+ end
82
+ end
83
+
84
+ describe '.u_strip()' do
85
+ it 'should allow nil' do
86
+ expect(util.u_strip(nil)).must_be_nil
87
+ end
88
+
89
+ it 'should strip all spaces' do
90
+ expect(util.u_strip(spaces_x)).must_equal 'x'
91
+ end
92
+ end
93
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssc.bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Jonathan Bradley Whited (@esotericpig)
8
- autorequire:
7
+ - Jonathan Bradley Whited
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-09 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attr_bool
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: '2.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.1'
40
+ version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '6.2'
75
+ version: '6.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '6.2'
82
+ version: '6.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: redcarpet
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -124,11 +124,12 @@ dependencies:
124
124
  version: '1.2'
125
125
  description: Simple Subspace Continuum Bot library.
126
126
  email:
127
- - bradley@esotericpig.com
127
+ - code@esotericpig.com
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".yardopts"
132
133
  - CHANGELOG.md
133
134
  - Gemfile
134
135
  - LICENSE.txt
@@ -141,23 +142,27 @@ files:
141
142
  - lib/ssc.bot/chat_log/message_parser.rb
142
143
  - lib/ssc.bot/chat_log/messages.rb
143
144
  - lib/ssc.bot/chat_log_file.rb
145
+ - lib/ssc.bot/clu.rb
144
146
  - lib/ssc.bot/error.rb
147
+ - lib/ssc.bot/jruby.rb
145
148
  - lib/ssc.bot/ssc_file.rb
149
+ - lib/ssc.bot/user.rb
146
150
  - lib/ssc.bot/user/jrobot_message_sender.rb
147
151
  - lib/ssc.bot/user/message_sender.rb
148
152
  - lib/ssc.bot/util.rb
149
153
  - lib/ssc.bot/version.rb
150
154
  - ssc.bot.gemspec
151
155
  - test/test_helper.rb
156
+ - test/util_test.rb
152
157
  homepage: https://github.com/esotericpig/ssc.bot
153
158
  licenses:
154
159
  - LGPL-3.0-or-later
155
160
  metadata:
156
- bug_tracker_uri: https://github.com/esotericpig/ssc.bot/issues
157
- changelog_uri: https://github.com/esotericpig/ssc.bot/blob/master/CHANGELOG.md
158
161
  homepage_uri: https://github.com/esotericpig/ssc.bot
159
162
  source_code_uri: https://github.com/esotericpig/ssc.bot
160
- post_install_message:
163
+ bug_tracker_uri: https://github.com/esotericpig/ssc.bot/issues
164
+ changelog_uri: https://github.com/esotericpig/ssc.bot/blob/master/CHANGELOG.md
165
+ post_install_message:
161
166
  rdoc_options: []
162
167
  require_paths:
163
168
  - lib
@@ -172,8 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
177
  - !ruby/object:Gem::Version
173
178
  version: '0'
174
179
  requirements: []
175
- rubygems_version: 3.1.2
176
- signing_key:
180
+ rubygems_version: 3.2.15
181
+ signing_key:
177
182
  specification_version: 4
178
183
  summary: Simple Subspace Continuum Bot library.
179
184
  test_files: []