render-text-helper 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/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +57 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +12 -0
- data/lib/render/text/helper/boolean.rb +28 -0
- data/lib/render/text/helper/string.rb +11 -0
- data/lib/render/text/helper/version.rb +9 -0
- data/lib/render/text/helper.rb +14 -0
- data/render-text-helper.gemspec +39 -0
- data/sig/render/text/helper/boolean.rbs +17 -0
- data/sig/render/text/helper/string.rbs +9 -0
- data/sig/render/text/helper.rbs +8 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9fa3bf802a34b87ba97a5adde26041af9da76aa1897a6cb671e5d3f854e87bb7
|
4
|
+
data.tar.gz: 7e3acb894a0defcfb02e07bb8eb16b4c1b1ebabe2374f4f147c5b7f15f9f1b71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90167a134c6dab5ee393ddffd1e9e2833b40692d54c733572c47b2edd2c6a796ba6a978c58aec2282370a1afeb88cf28eeda4fbc30578e7a33df133c58566877
|
7
|
+
data.tar.gz: 66291f7ae3b137077a43b84836e8bbcfc608bed12ba2ab6152daadb6842d4058fea352bdac6d54dd49b25fa29a9311a7b9a7e9d07e88b4dce0932885129de8d5
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
render-text-helper (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
json (2.6.2)
|
12
|
+
parallel (1.22.1)
|
13
|
+
parser (3.1.2.1)
|
14
|
+
ast (~> 2.4.1)
|
15
|
+
rainbow (3.1.1)
|
16
|
+
rake (13.0.6)
|
17
|
+
regexp_parser (2.5.0)
|
18
|
+
rexml (3.2.5)
|
19
|
+
rspec (3.11.0)
|
20
|
+
rspec-core (~> 3.11.0)
|
21
|
+
rspec-expectations (~> 3.11.0)
|
22
|
+
rspec-mocks (~> 3.11.0)
|
23
|
+
rspec-core (3.11.0)
|
24
|
+
rspec-support (~> 3.11.0)
|
25
|
+
rspec-expectations (3.11.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.11.0)
|
28
|
+
rspec-mocks (3.11.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.11.0)
|
31
|
+
rspec-support (3.11.0)
|
32
|
+
rubocop (1.35.0)
|
33
|
+
json (~> 2.3)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.1.2.1)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml (>= 3.2.5, < 4.0)
|
39
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.21.0)
|
43
|
+
parser (>= 3.1.1.0)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
unicode-display_width (2.2.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
x86_64-linux
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
rake (~> 13.0)
|
52
|
+
render-text-helper!
|
53
|
+
rspec (~> 3.0)
|
54
|
+
rubocop (~> 1.21)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
2.3.20
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Saimon Lovell
|
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,79 @@
|
|
1
|
+
# Render::Text::Helper
|
2
|
+
|
3
|
+
This gem extends text manipulation to classes like String, Boolean etc..
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add render-text-helper
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install render-text-helper
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Limit Print
|
18
|
+
|
19
|
+
This function makes sure that the string does not go over a specific given limit.
|
20
|
+
It has two parameters "limit" which is defaulted to 32 and "more_indicator" which
|
21
|
+
defaults to "."
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
'hello'.limit_print
|
25
|
+
'hello'
|
26
|
+
|
27
|
+
'elephant'.limit_print(limit: 2)
|
28
|
+
'el...'
|
29
|
+
|
30
|
+
'elephant'.limit_print(limit: 2, more_indicator: '')
|
31
|
+
'el'
|
32
|
+
|
33
|
+
'elephant'.limit_print(limit: 3, more_indicator: '_')
|
34
|
+
'ele___'
|
35
|
+
```
|
36
|
+
|
37
|
+
### to yes no
|
38
|
+
|
39
|
+
This function returns a string from a boolean to yes or no.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
true.to_yes_no
|
43
|
+
'yes'
|
44
|
+
|
45
|
+
true.to_yes_no(capital_letter: true)
|
46
|
+
'YES'
|
47
|
+
|
48
|
+
false.to_yes_no
|
49
|
+
'no'
|
50
|
+
|
51
|
+
false.to_yes_no(capital_letter: true)
|
52
|
+
'NO'
|
53
|
+
```
|
54
|
+
|
55
|
+
### to yn
|
56
|
+
|
57
|
+
This function returns a string from a boolean to Y or N
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
true.to_yn
|
61
|
+
'Y'
|
62
|
+
|
63
|
+
true.to_yn(capital_letter: false)
|
64
|
+
'y'
|
65
|
+
|
66
|
+
false.to_yn
|
67
|
+
'N'
|
68
|
+
|
69
|
+
false.to_yn(capital_letter: false)
|
70
|
+
'n'
|
71
|
+
```
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SaimonL/render-text-helper
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Added methods to boolean module
|
4
|
+
module BooleanHelper
|
5
|
+
def to_yn(capital_letter: true)
|
6
|
+
if self
|
7
|
+
capital_letter ? 'Y' : 'y'
|
8
|
+
else
|
9
|
+
capital_letter ? 'N' : 'n'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_yes_no(capital_letter: false)
|
14
|
+
if self
|
15
|
+
capital_letter ? 'YES' : 'yes'
|
16
|
+
else
|
17
|
+
capital_letter ? 'NO' : 'no'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class TrueClass
|
23
|
+
include BooleanHelper
|
24
|
+
end
|
25
|
+
|
26
|
+
class FalseClass
|
27
|
+
include BooleanHelper
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Adds function to existing String class
|
4
|
+
class String
|
5
|
+
# output the string giving the limit. It does not touch the string
|
6
|
+
def limit_print(limit: 32, more_indicator: '.')
|
7
|
+
return self if size < limit
|
8
|
+
|
9
|
+
[self[0...limit], more_indicator, more_indicator, more_indicator].join
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper/version'
|
4
|
+
require_relative 'helper/string'
|
5
|
+
require_relative 'helper/boolean'
|
6
|
+
|
7
|
+
module Render
|
8
|
+
module Text
|
9
|
+
module Helper
|
10
|
+
class Error < StandardError; end
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/render/text/helper/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'render-text-helper'
|
7
|
+
spec.version = Render::Text::Helper::VERSION
|
8
|
+
spec.authors = ['Saimon Lovell']
|
9
|
+
spec.email = ['staysynchronize@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Does some string malnutrition'
|
12
|
+
spec.description = 'Limit the render text, convert boolean to text etc'
|
13
|
+
spec.homepage = 'https://github.com/SaimonL/render-text-helper'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.6.0'
|
16
|
+
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/SaimonL/render-text-helper'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/SaimonL/render-text-helper/blob/master/CHANGELOG.md'
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Render
|
2
|
+
module Text
|
3
|
+
module Helper
|
4
|
+
class TrueClass
|
5
|
+
def to_yn: (capital_letter: bool) -> String
|
6
|
+
|
7
|
+
def to_yes_no: (capital_letter: bool) -> String
|
8
|
+
end
|
9
|
+
|
10
|
+
class FalseClass
|
11
|
+
def to_yn: (capital_letter: bool) -> String
|
12
|
+
|
13
|
+
def to_yes_no: (capital_letter: bool) -> String
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: render-text-helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Saimon Lovell
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Limit the render text, convert boolean to text etc
|
14
|
+
email:
|
15
|
+
- staysynchronize@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/render/text/helper.rb
|
29
|
+
- lib/render/text/helper/boolean.rb
|
30
|
+
- lib/render/text/helper/string.rb
|
31
|
+
- lib/render/text/helper/version.rb
|
32
|
+
- render-text-helper.gemspec
|
33
|
+
- sig/render/text/helper.rbs
|
34
|
+
- sig/render/text/helper/boolean.rbs
|
35
|
+
- sig/render/text/helper/string.rbs
|
36
|
+
homepage: https://github.com/SaimonL/render-text-helper
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
allowed_push_host: https://rubygems.org
|
41
|
+
homepage_uri: https://github.com/SaimonL/render-text-helper
|
42
|
+
source_code_uri: https://github.com/SaimonL/render-text-helper
|
43
|
+
changelog_uri: https://github.com/SaimonL/render-text-helper/blob/master/CHANGELOG.md
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.6.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.3.20
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Does some string malnutrition
|
63
|
+
test_files: []
|