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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c05fb67e627a48333959a2e5939faf1ef73fec35c8bc3cb81f106452089797c
4
- data.tar.gz: 4196eaefe1dbf1ba369d2c35248ae762653e842b8f371529241d9a730caa9773
3
+ metadata.gz: f3e00b5825661c9c4fd7a4dc9d98f1ba2e2bee79287ee92dc500577a822b640d
4
+ data.tar.gz: a36bd9c135be5d2aeb1831e6673059c4d1d3ad0e55de4ae560200316a49209c1
5
5
  SHA512:
6
- metadata.gz: 5b870d389d1f990a94af3a5f381c486eb144c7984704c97f75fd0ebd8fc66788583de8b58067e509ca9a3a4bc202d56b699125f336aaa04f5cb0254507536d9a
7
- data.tar.gz: 39e19c22d146df6356ded9ebf56297fb9dadaf681eab7e4a15081c3ff04a1ab8d30a8035ca811a090e6c98faa9a129b72c2a8abb9f1058b4783e671033dc7b08
6
+ metadata.gz: 63dd527b450d3bda6eed773830ddcf1296a5dbaddc2f7ffccf2d51a85e06b3eb3d3800de614be24aca7e5c8b2c1c4a3251c99bbbecd9e425e7ad469adbfe202b
7
+ data.tar.gz: df4702c055f20d2020cd053a10d9765149828d29c9fd966dd4c5252ad7c183faab75b0f786577c54996fdcc53ba735c544faf3d57c43753d5d242c55dca46590
data/.rubocop.yml CHANGED
@@ -19,4 +19,10 @@ Layout/EndOfLine:
19
19
  Style/EvalWithLocation:
20
20
  Enabled: false
21
21
  Metrics/AbcSize:
22
- Max: 25
22
+ Max: 30
23
+ Metrics/CyclomaticComplexity:
24
+ Max: 10
25
+ Metrics/PerceivedComplexity:
26
+ Max: 10
27
+ Metrics/MethodLength:
28
+ Max: 30
data/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](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.0'
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 95
19
- SimpleCov.minimum_coverage_by_file 90
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/'
@@ -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',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellipsized
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko