File: utils.rb

package info (click to toggle)
ruby-semver-dialects 3.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 156 kB
  • sloc: ruby: 1,537; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

# monkey-patch String class
class String
  def unwrap
    s = self
    s = s[1..s.length - 1] if s.start_with?('(')
    s = s[0..s.length - 2] if s.end_with?(')')
    s
  end

  def range_present?
    !empty?
  end

  def number?
    !!Integer(self, exception: false)
  end

  def initial
    self[0, 1]
  end

  def unquote
    delete_suffix('"').delete_prefix('"').delete_suffix('\'').delete_prefix('\'')
  end

  def csv_unquote
    unquote.unquote.unquote
  end

  def remove_trailing_number
    gsub(/([^\d]*)\d+$/, '\1')
  end

  def chars_only
    gsub(/[^0-9A-Za-z]/, '')
  end
end