Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/utils.rb

Overview

monkey-patch String class

Instance Method Summary collapse

Instance Method Details

#chars_onlyObject



36
37
38
# File 'lib/utils.rb', line 36

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

#csv_unquoteObject



28
29
30
# File 'lib/utils.rb', line 28

def csv_unquote
  unquote.unquote.unquote
end

#initialObject



20
21
22
# File 'lib/utils.rb', line 20

def initial
  self[0, 1]
end

#number?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/utils.rb', line 16

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

#range_present?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/utils.rb', line 12

def range_present?
  !empty?
end

#remove_trailing_numberObject



32
33
34
# File 'lib/utils.rb', line 32

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

#unquoteObject



24
25
26
# File 'lib/utils.rb', line 24

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

#unwrapObject



5
6
7
8
9
10
# File 'lib/utils.rb', line 5

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