ellipsized 0.1.0 → 0.1.1
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 +4 -4
- data/.rubocop.yml +7 -1
- data/README.md +3 -1
- data/ellipsized.gemspec +1 -1
- data/lib/ellipsized.rb +5 -0
- data/test/test__helper.rb +2 -2
- data/test/test_ellipsized.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3e00b5825661c9c4fd7a4dc9d98f1ba2e2bee79287ee92dc500577a822b640d
|
4
|
+
data.tar.gz: a36bd9c135be5d2aeb1831e6673059c4d1d3ad0e55de4ae560200316a49209c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63dd527b450d3bda6eed773830ddcf1296a5dbaddc2f7ffccf2d51a85e06b3eb3d3800de614be24aca7e5c8b2c1c4a3251c99bbbecd9e425e7ad469adbfe202b
|
7
|
+
data.tar.gz: df4702c055f20d2020cd053a10d9765149828d29c9fd966dd4c5252ad7c183faab75b0f786577c54996fdcc53ba735c544faf3d57c43753d5d242c55dca46590
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
[](https://github.com/yegor256/ellipsized/blob/master/LICENSE.txt)
|
13
13
|
|
14
14
|
It makes a string fit into a required length by replacing
|
15
|
-
part of it in the middle with an ellipsis:
|
15
|
+
part of it in the middle with an [ellipsis]:
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
require 'ellipsized'
|
@@ -54,3 +54,5 @@ bundle exec rake
|
|
54
54
|
```
|
55
55
|
|
56
56
|
If it's clean and you don't see any error messages, submit your pull request.
|
57
|
+
|
58
|
+
[ellipsis]: https://en.wikipedia.org/wiki/Ellipsis
|
data/ellipsized.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
10
10
|
s.required_ruby_version = '>=3.2'
|
11
11
|
s.name = 'ellipsized'
|
12
|
-
s.version = '0.1.
|
12
|
+
s.version = '0.1.1'
|
13
13
|
s.license = 'MIT'
|
14
14
|
s.summary = 'A simple Ruby gem that adds a .ellipsized() method to String'
|
15
15
|
s.description =
|
data/lib/ellipsized.rb
CHANGED
@@ -36,9 +36,14 @@ class String
|
|
36
36
|
# "xyz".ellipsized(0) # => ""
|
37
37
|
# "xyz".ellipsized(2, gap: "...") # => "xy"
|
38
38
|
def ellipsized(max = 64, gap: '...')
|
39
|
+
raise "Max length must be an Integer, while #{max.class.name} provided" unless max.is_a?(Integer)
|
40
|
+
raise "Max length (#{max}) is negative" if max.negative?
|
39
41
|
return '' if empty?
|
40
42
|
return self if length <= max
|
41
43
|
return '' if max.zero?
|
44
|
+
raise "The gap doesn't implement to_s()" unless gap.respond_to?(:to_s)
|
45
|
+
|
46
|
+
gap = gap.to_s
|
42
47
|
return self[0..max - 1] if gap.length >= max
|
43
48
|
|
44
49
|
head = tail = (max - gap.length) / 2
|
data/test/test__helper.rb
CHANGED
@@ -15,8 +15,8 @@ unless SimpleCov.running || ENV['PICKS']
|
|
15
15
|
SimpleCov::Formatter::CoberturaFormatter
|
16
16
|
]
|
17
17
|
)
|
18
|
-
SimpleCov.minimum_coverage
|
19
|
-
SimpleCov.minimum_coverage_by_file
|
18
|
+
SimpleCov.minimum_coverage 100
|
19
|
+
SimpleCov.minimum_coverage_by_file 100
|
20
20
|
SimpleCov.start do
|
21
21
|
add_filter 'test/'
|
22
22
|
add_filter 'vendor/'
|
data/test/test_ellipsized.rb
CHANGED
@@ -30,6 +30,16 @@ class TestEllipsized < Minitest::Test
|
|
30
30
|
assert_equal('The...er', 'The Godfather'.ellipsized(8))
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_with_empty_gap
|
34
|
+
assert_equal('', 'Encapsulation'.ellipsized(0, gap: ''))
|
35
|
+
assert_equal('E', 'Encapsulation'.ellipsized(1, gap: ''))
|
36
|
+
assert_equal('En', 'Encapsulation'.ellipsized(2, gap: ''))
|
37
|
+
assert_equal('Enn', 'Encapsulation'.ellipsized(3, gap: ''))
|
38
|
+
assert_equal('Enon', 'Encapsulation'.ellipsized(4, gap: ''))
|
39
|
+
assert_equal('Encon', 'Encapsulation'.ellipsized(5, gap: ''))
|
40
|
+
assert_equal('Encion', 'Encapsulation'.ellipsized(6, gap: ''))
|
41
|
+
end
|
42
|
+
|
33
43
|
def test_with_replacement
|
34
44
|
assert_equal(
|
35
45
|
'This .. skip ..indow',
|