coolkit 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +149 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/bin/setup +9 -0
- data/coolkit.gemspec +37 -0
- data/lib/coolkit/array/remove_first.rb +21 -0
- data/lib/coolkit/error.rb +5 -0
- data/lib/coolkit/filesystem.rb +14 -0
- data/lib/coolkit/paths.rb +19 -0
- data/lib/coolkit/string/comment.rb +20 -0
- data/lib/coolkit/string/indent.rb +42 -0
- data/lib/coolkit/string/titleize.rb +24 -0
- data/lib/coolkit/symbolize.rb +31 -0
- data/lib/coolkit/time.rb +13 -0
- data/lib/coolkit/version.rb +3 -0
- data/lib/coolkit.rb +4 -0
- metadata +167 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a5824a5224b213f0f640864757a042cddff2994a46450066b5cbb7438604a95b
|
|
4
|
+
data.tar.gz: 43a8a6ea69ae91e8389f0b730c5d88544004821d6494926bc0e5c618f853c2c1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5c6c1b58118ec3b4ab741bcdd5fefc5cc9b5f3005c884a8a8826616b306792817137d9a25f0e161f6e2c3c3d63726b1bf295adc42ab63bf6015d9931280984f0
|
|
7
|
+
data.tar.gz: 607c920e59c12184e2fb16cd42166556b3951f8f6740f812e13fb0932ee7b4fa633f02afa29f0e57bb49080ad2161441cb28b039680dbf63abf3c8a395c057df
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.3.0
|
|
3
|
+
|
|
4
|
+
Style/Documentation:
|
|
5
|
+
Enabled: true
|
|
6
|
+
Exclude:
|
|
7
|
+
- 'test/**/*.rb'
|
|
8
|
+
|
|
9
|
+
Style/DocumentationMethod:
|
|
10
|
+
Enabled: true
|
|
11
|
+
Exclude:
|
|
12
|
+
- 'test/**/*.rb'
|
|
13
|
+
|
|
14
|
+
# Don't leave calls to pry lying around.
|
|
15
|
+
Lint/Debugger:
|
|
16
|
+
Enabled: true
|
|
17
|
+
|
|
18
|
+
# ==============================================================================
|
|
19
|
+
# Layout
|
|
20
|
+
# ==============================================================================
|
|
21
|
+
|
|
22
|
+
Metrics/LineLength:
|
|
23
|
+
Max: 150
|
|
24
|
+
|
|
25
|
+
Layout/EmptyLineAfterGuardClause:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
29
|
+
Enabled: false
|
|
30
|
+
|
|
31
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
35
|
+
Enabled: false
|
|
36
|
+
|
|
37
|
+
# https://unix.stackexchange.com/a/18789
|
|
38
|
+
Layout/TrailingBlankLines:
|
|
39
|
+
EnforcedStyle: final_newline
|
|
40
|
+
|
|
41
|
+
# ==============================================================================
|
|
42
|
+
# Strings
|
|
43
|
+
# ==============================================================================
|
|
44
|
+
|
|
45
|
+
Style/StringLiterals:
|
|
46
|
+
EnforcedStyle: double_quotes
|
|
47
|
+
|
|
48
|
+
Style/FrozenStringLiteralComment:
|
|
49
|
+
Enabled: false
|
|
50
|
+
|
|
51
|
+
Naming/HeredocDelimiterNaming:
|
|
52
|
+
Enabled: false
|
|
53
|
+
|
|
54
|
+
# ==============================================================================
|
|
55
|
+
# Numbers
|
|
56
|
+
# ==============================================================================
|
|
57
|
+
|
|
58
|
+
Style/ZeroLengthPredicate:
|
|
59
|
+
Enabled: false
|
|
60
|
+
|
|
61
|
+
Style/NumericPredicate:
|
|
62
|
+
Enabled: false
|
|
63
|
+
|
|
64
|
+
Naming/VariableNumber:
|
|
65
|
+
EnforcedStyle: snake_case
|
|
66
|
+
|
|
67
|
+
# ==============================================================================
|
|
68
|
+
# Braces, Brackets, & Parens
|
|
69
|
+
# ==============================================================================
|
|
70
|
+
|
|
71
|
+
Style/DefWithParentheses:
|
|
72
|
+
Enabled: false
|
|
73
|
+
|
|
74
|
+
Style/MethodCallWithoutArgsParentheses:
|
|
75
|
+
Enabled: false
|
|
76
|
+
|
|
77
|
+
# Only use braces if the function expects a hash argument. [different in Ruby 2.7+](https://blog.saeloun.com/2019/10/07/ruby-2-7-keyword-arguments-redesign.html)
|
|
78
|
+
Style/BracesAroundHashParameters:
|
|
79
|
+
Enabled: false
|
|
80
|
+
|
|
81
|
+
Style/WordArray:
|
|
82
|
+
EnforcedStyle: brackets
|
|
83
|
+
|
|
84
|
+
Style/SymbolArray:
|
|
85
|
+
EnforcedStyle: brackets
|
|
86
|
+
|
|
87
|
+
# ==============================================================================
|
|
88
|
+
# Unsorted
|
|
89
|
+
# ==============================================================================
|
|
90
|
+
|
|
91
|
+
Layout/IndentFirstHashElement:
|
|
92
|
+
EnforcedStyle: consistent
|
|
93
|
+
|
|
94
|
+
Layout/IndentFirstArrayElement:
|
|
95
|
+
EnforcedStyle: consistent
|
|
96
|
+
|
|
97
|
+
Style/TrailingCommaInArguments:
|
|
98
|
+
EnforcedStyleForMultiline: comma
|
|
99
|
+
|
|
100
|
+
Style/TrailingCommaInArrayLiteral:
|
|
101
|
+
EnforcedStyleForMultiline: comma
|
|
102
|
+
|
|
103
|
+
Style/TrailingCommaInHashLiteral:
|
|
104
|
+
EnforcedStyleForMultiline: comma
|
|
105
|
+
|
|
106
|
+
# Explicit, not redundant
|
|
107
|
+
Style/RedundantReturn:
|
|
108
|
+
Enabled: false
|
|
109
|
+
|
|
110
|
+
# Explicit, not redundant
|
|
111
|
+
Style/RedundantSelf:
|
|
112
|
+
Enabled: false
|
|
113
|
+
|
|
114
|
+
# `x&.y&.[](:argument)` isn't what I'd call "readable".
|
|
115
|
+
# https://stackoverflow.com/questions/34794697/using-with-the-safe-navigation-operator-in-ruby
|
|
116
|
+
Style/SafeNavigation:
|
|
117
|
+
Enabled: false
|
|
118
|
+
|
|
119
|
+
# TODO: File issue to ignore enums when using `EnforcedStyle: assign_inside_condition`.
|
|
120
|
+
Style/ConditionalAssignment:
|
|
121
|
+
Enabled: false
|
|
122
|
+
|
|
123
|
+
Lint/HandleExceptions:
|
|
124
|
+
AllowComments: true
|
|
125
|
+
|
|
126
|
+
Metrics/ModuleLength:
|
|
127
|
+
Enabled: false
|
|
128
|
+
|
|
129
|
+
Metrics/ClassLength:
|
|
130
|
+
Enabled: false
|
|
131
|
+
|
|
132
|
+
Metrics/MethodLength:
|
|
133
|
+
Enabled: false
|
|
134
|
+
|
|
135
|
+
Metrics/BlockLength:
|
|
136
|
+
Enabled: false
|
|
137
|
+
|
|
138
|
+
Metrics/AbcSize:
|
|
139
|
+
Enabled: false
|
|
140
|
+
|
|
141
|
+
Metrics/CyclomaticComplexity:
|
|
142
|
+
Enabled: false
|
|
143
|
+
|
|
144
|
+
Metrics/PerceivedComplexity:
|
|
145
|
+
Enabled: false
|
|
146
|
+
|
|
147
|
+
Style/CommentedKeyword:
|
|
148
|
+
Enabled: False
|
|
149
|
+
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
<!-- ## [Unreleased] -->
|
|
9
|
+
|
|
10
|
+
## 0.1.0 (2019-11-17)
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `Coolkit::Error` and `Coolkit::VERSION`.
|
|
15
|
+
- `root_dir`, `data_dir`, `data_dir` for finding your way without `Rails.root`
|
|
16
|
+
- `symbolize_keys` to get by without .
|
|
17
|
+
- `to_est` to convert UCT time to EST.
|
|
18
|
+
- `write_to_file` to write to a given path and not worry if parent folders exist yet.
|
|
19
|
+
- `Array#remove_first` to remove the first *x* from an array.
|
|
20
|
+
- `String#indent` from ActiveSupport. (Because it's excessive to require it for just that)
|
|
21
|
+
- `String#comment` to comment ruby code in strings.
|
|
22
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
coolkit (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ansi (1.5.0)
|
|
10
|
+
builder (3.2.3)
|
|
11
|
+
coveralls (0.8.23)
|
|
12
|
+
json (>= 1.8, < 3)
|
|
13
|
+
simplecov (~> 0.16.1)
|
|
14
|
+
term-ansicolor (~> 1.3)
|
|
15
|
+
thor (>= 0.19.4, < 2.0)
|
|
16
|
+
tins (~> 1.6)
|
|
17
|
+
docile (1.3.2)
|
|
18
|
+
json (2.2.0)
|
|
19
|
+
minitest (5.13.0)
|
|
20
|
+
minitest-focus (1.1.2)
|
|
21
|
+
minitest (>= 4, < 6)
|
|
22
|
+
minitest-reporters (1.4.2)
|
|
23
|
+
ansi
|
|
24
|
+
builder
|
|
25
|
+
minitest (>= 5.0)
|
|
26
|
+
ruby-progressbar
|
|
27
|
+
rake (10.5.0)
|
|
28
|
+
ruby-progressbar (1.10.1)
|
|
29
|
+
simplecov (0.16.1)
|
|
30
|
+
docile (~> 1.1)
|
|
31
|
+
json (>= 1.8, < 3)
|
|
32
|
+
simplecov-html (~> 0.10.0)
|
|
33
|
+
simplecov-html (0.10.2)
|
|
34
|
+
term-ansicolor (1.7.1)
|
|
35
|
+
tins (~> 1.0)
|
|
36
|
+
thor (0.20.3)
|
|
37
|
+
tins (1.22.2)
|
|
38
|
+
|
|
39
|
+
PLATFORMS
|
|
40
|
+
ruby
|
|
41
|
+
|
|
42
|
+
DEPENDENCIES
|
|
43
|
+
bundler (~> 2.0)
|
|
44
|
+
coolkit!
|
|
45
|
+
coveralls (~> 0.8.23)
|
|
46
|
+
minitest (~> 5.0)
|
|
47
|
+
minitest-focus (~> 1.1)
|
|
48
|
+
minitest-reporters (~> 1.4)
|
|
49
|
+
rake (~> 10.0)
|
|
50
|
+
simplecov
|
|
51
|
+
|
|
52
|
+
BUNDLED WITH
|
|
53
|
+
2.0.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Clay Dunston
|
|
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,41 @@
|
|
|
1
|
+
# Coolkit
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/tcd/coolkit)
|
|
4
|
+
[](https://coveralls.io/github/tcd/coolkit?branch=master)
|
|
5
|
+
[](https://github.com/tcd/coolkit/blob/master/LICENSE.txt)
|
|
6
|
+
|
|
7
|
+
Useful ruby code with no dependencies.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem "coolkit"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
And then execute:
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
bundle
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
gem install util
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
require "coolkit"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Contributing
|
|
36
|
+
|
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tcd/coolkit.
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/coolkit.gemspec
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "coolkit/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "coolkit"
|
|
7
|
+
spec.version = Coolkit::VERSION
|
|
8
|
+
spec.authors = ["Clay Dunston"]
|
|
9
|
+
spec.email = ["dunstontc@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Useful ruby code with no dependencies."
|
|
12
|
+
spec.homepage = "https://github.com/tcd/coolkit"
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
|
|
15
|
+
spec.metadata = {
|
|
16
|
+
"homepage_uri" => spec.homepage,
|
|
17
|
+
"source_code_uri" => spec.homepage,
|
|
18
|
+
"changelog_uri" => spec.homepage,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = "exe"
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ["lib"]
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
31
|
+
spec.add_development_dependency "coveralls", "~> 0.8.23"
|
|
32
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
33
|
+
spec.add_development_dependency "minitest-focus", "~> 1.1"
|
|
34
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.4"
|
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
36
|
+
spec.add_development_dependency "simplecov"
|
|
37
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
# Remove the first instance of an item from an array.
|
|
3
|
+
# **Note**: this will mutate the reciever.
|
|
4
|
+
#
|
|
5
|
+
# @param item [Object]
|
|
6
|
+
# @return [self]
|
|
7
|
+
def remove_first!(item)
|
|
8
|
+
return self if self.length == 0
|
|
9
|
+
index = self.index(item)
|
|
10
|
+
self.delete_at(index) if index
|
|
11
|
+
return self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Return a copy of an array the first instance of a given item removed.
|
|
15
|
+
#
|
|
16
|
+
# @param item [Object]
|
|
17
|
+
# @return [self]
|
|
18
|
+
def remove_first(item)
|
|
19
|
+
return self.dup.tap { |s| s.remove_first!(item) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
|
|
3
|
+
module Coolkit
|
|
4
|
+
# Append data to the end of a file.
|
|
5
|
+
# The file is created if it doesn"t exist.
|
|
6
|
+
#
|
|
7
|
+
# @param file [String] Path to the file.
|
|
8
|
+
# @param data [String,#to_s] Data to write to the file.
|
|
9
|
+
# @return [void]
|
|
10
|
+
def self.write_to_file(file, data)
|
|
11
|
+
FileUtils.mkdir_p(File.dirname(file))
|
|
12
|
+
File.open(file, "a") { |f| f.write(data) }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Coolkit
|
|
2
|
+
# Directory where the gem is located.
|
|
3
|
+
# @return [String]
|
|
4
|
+
def self.root_dir
|
|
5
|
+
return File.expand_path("../../..", __FILE__)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Directory for writing out files.
|
|
9
|
+
# @return [String]
|
|
10
|
+
def self.data_dir
|
|
11
|
+
return File.join(self.root_dir, "data")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Directory for writing out files.
|
|
15
|
+
# @return [String]
|
|
16
|
+
def self.tmp_dir
|
|
17
|
+
return File.join(self.root_dir, "tmp")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class String
|
|
2
|
+
|
|
3
|
+
# Adds a comment string (`"# "`) after every newline in a string.
|
|
4
|
+
#
|
|
5
|
+
# @param indent_empty_lines [Boolean]
|
|
6
|
+
# @return [void]
|
|
7
|
+
def comment!(indent_empty_lines = true)
|
|
8
|
+
re = indent_empty_lines ? /^/ : /^(?!$)/
|
|
9
|
+
gsub!(re, "# ")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Returns a copy of a string with a comment (`"# "`) after every newline in a string.
|
|
13
|
+
#
|
|
14
|
+
# @param indent_empty_lines [Boolean]
|
|
15
|
+
# @return [String]
|
|
16
|
+
def comment(indent_empty_lines = true)
|
|
17
|
+
dup.tap { |s| s.comment!(indent_empty_lines) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Straight from [ActiveSupport][1]
|
|
2
|
+
#
|
|
3
|
+
# [1]:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/indent.rb
|
|
4
|
+
class String
|
|
5
|
+
|
|
6
|
+
# Same as {indent}, except it indents the receiver in-place.
|
|
7
|
+
#
|
|
8
|
+
# Returns the indented string, or `nil` if there was nothing to indent.
|
|
9
|
+
#
|
|
10
|
+
# @param amount [Integer] The level of indentation to add.
|
|
11
|
+
# @param indent_string [String] Defaults to tab if a tab is present in the string, and `" "` otherwise.
|
|
12
|
+
# @param indent_empty_lines [Boolean]
|
|
13
|
+
#
|
|
14
|
+
# @return [void]
|
|
15
|
+
def indent!(amount, indent_string = nil, indent_empty_lines = false)
|
|
16
|
+
indent_string = indent_string || self[/^[ \t]/] || " "
|
|
17
|
+
re = indent_empty_lines ? /^/ : /^(?!$)/
|
|
18
|
+
gsub!(re, indent_string * amount)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Indents the lines in the receiver.
|
|
22
|
+
#
|
|
23
|
+
# The second argument, `indent_string`, specifies which indent string to
|
|
24
|
+
# use. The default is `nil`, which tells the method to make a guess by
|
|
25
|
+
# peeking at the first indented line, and fallback to a space if there is
|
|
26
|
+
# none.
|
|
27
|
+
#
|
|
28
|
+
# While `indent_string` is typically one space or tab, it may be any string.
|
|
29
|
+
#
|
|
30
|
+
# The third argument, `indent_empty_lines`, is a flag that says whether
|
|
31
|
+
# empty lines should be indented. Default is `false`.
|
|
32
|
+
#
|
|
33
|
+
# @param amount [Integer] The level of indentation to add.
|
|
34
|
+
# @param indent_string [String] Defaults to tab if a tab is present in the string, and `" "` otherwise.
|
|
35
|
+
# @param indent_empty_lines [Boolean]
|
|
36
|
+
#
|
|
37
|
+
# @return [String]
|
|
38
|
+
def indent(amount, indent_string = nil, indent_empty_lines = false)
|
|
39
|
+
dup.tap { |s| s.indent!(amount, indent_string, indent_empty_lines) }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# class String
|
|
2
|
+
#
|
|
3
|
+
# # Returns a copy of a string with the first letter of each word capitalized.
|
|
4
|
+
# # @return [String]
|
|
5
|
+
# def titleize()
|
|
6
|
+
# return self.split(" ")
|
|
7
|
+
# .map(&:capitalize!)
|
|
8
|
+
# .join(" ")
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# # @return [String]
|
|
12
|
+
# def titleize2(string)
|
|
13
|
+
# words = self.split(" ")
|
|
14
|
+
# skips = ["and", "of", "the", "in", "to", "over", "an", "a"]
|
|
15
|
+
# words.each do |word|
|
|
16
|
+
# if word == words[0] || !skips.include?(word)
|
|
17
|
+
# element.capitalize!
|
|
18
|
+
# end
|
|
19
|
+
# end
|
|
20
|
+
# answer = array.join(" ")
|
|
21
|
+
# return answer
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Coolkit
|
|
2
|
+
# Recursively convert keys in a Hash or Array to symbols.
|
|
3
|
+
#
|
|
4
|
+
# See:
|
|
5
|
+
# - [original code](https://avdi.codes/recursively-symbolize-keys/)
|
|
6
|
+
# - [array support](https://gist.github.com/neektza/8585746)
|
|
7
|
+
#
|
|
8
|
+
# @param arg [Hash,Array]
|
|
9
|
+
# @return [Hash,Array]
|
|
10
|
+
def self.symbolize_keys(arg)
|
|
11
|
+
if arg.is_a?(Hash)
|
|
12
|
+
arg.inject({}) do |result, (key, value)|
|
|
13
|
+
new_key = case key
|
|
14
|
+
when String then key.to_sym()
|
|
15
|
+
else key
|
|
16
|
+
end
|
|
17
|
+
new_value = case value
|
|
18
|
+
when Hash then symbolize_keys(value)
|
|
19
|
+
when Array then symbolize_keys(value)
|
|
20
|
+
else value
|
|
21
|
+
end
|
|
22
|
+
result[new_key] = new_value
|
|
23
|
+
result
|
|
24
|
+
end
|
|
25
|
+
elsif arg.is_a?(Array)
|
|
26
|
+
arg.map { |e| symbolize_keys(e) }
|
|
27
|
+
else
|
|
28
|
+
x
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/coolkit/time.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "time"
|
|
2
|
+
|
|
3
|
+
module Coolkit
|
|
4
|
+
# Convert a `UTC` {Time} object to `EST`.
|
|
5
|
+
#
|
|
6
|
+
# @raise [ArgumentError] Unless passed a `UTC` formatted time.
|
|
7
|
+
# @param time [Time]
|
|
8
|
+
# @return [Time]
|
|
9
|
+
def self.to_est(time)
|
|
10
|
+
raise ArgumentError "argument is not in UTC format" unless time.utc?()
|
|
11
|
+
return time + Time.zone_offset("EST")
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/coolkit.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: coolkit
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Clay Dunston
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-11-17 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: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: coveralls
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.8.23
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.8.23
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: minitest-focus
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.1'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.1'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: minitest-reporters
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.4'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.4'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '10.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '10.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: simplecov
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
description:
|
|
112
|
+
email:
|
|
113
|
+
- dunstontc@gmail.com
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- ".rubocop.yml"
|
|
120
|
+
- ".travis.yml"
|
|
121
|
+
- CHANGELOG.md
|
|
122
|
+
- Gemfile
|
|
123
|
+
- Gemfile.lock
|
|
124
|
+
- LICENSE.txt
|
|
125
|
+
- README.md
|
|
126
|
+
- Rakefile
|
|
127
|
+
- bin/console
|
|
128
|
+
- bin/setup
|
|
129
|
+
- coolkit.gemspec
|
|
130
|
+
- lib/coolkit.rb
|
|
131
|
+
- lib/coolkit/array/remove_first.rb
|
|
132
|
+
- lib/coolkit/error.rb
|
|
133
|
+
- lib/coolkit/filesystem.rb
|
|
134
|
+
- lib/coolkit/paths.rb
|
|
135
|
+
- lib/coolkit/string/comment.rb
|
|
136
|
+
- lib/coolkit/string/indent.rb
|
|
137
|
+
- lib/coolkit/string/titleize.rb
|
|
138
|
+
- lib/coolkit/symbolize.rb
|
|
139
|
+
- lib/coolkit/time.rb
|
|
140
|
+
- lib/coolkit/version.rb
|
|
141
|
+
homepage: https://github.com/tcd/coolkit
|
|
142
|
+
licenses:
|
|
143
|
+
- MIT
|
|
144
|
+
metadata:
|
|
145
|
+
homepage_uri: https://github.com/tcd/coolkit
|
|
146
|
+
source_code_uri: https://github.com/tcd/coolkit
|
|
147
|
+
changelog_uri: https://github.com/tcd/coolkit
|
|
148
|
+
post_install_message:
|
|
149
|
+
rdoc_options: []
|
|
150
|
+
require_paths:
|
|
151
|
+
- lib
|
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
|
+
requirements:
|
|
154
|
+
- - ">="
|
|
155
|
+
- !ruby/object:Gem::Version
|
|
156
|
+
version: '0'
|
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
|
+
requirements:
|
|
159
|
+
- - ">="
|
|
160
|
+
- !ruby/object:Gem::Version
|
|
161
|
+
version: '0'
|
|
162
|
+
requirements: []
|
|
163
|
+
rubygems_version: 3.0.3
|
|
164
|
+
signing_key:
|
|
165
|
+
specification_version: 4
|
|
166
|
+
summary: Useful ruby code with no dependencies.
|
|
167
|
+
test_files: []
|