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



38
39
40
# File 'lib/utils.rb', line 38

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

#csv_unquoteObject



30
31
32
# File 'lib/utils.rb', line 30

def csv_unquote
  unquote.unquote.unquote
end

#initialObject



22
23
24
# File 'lib/utils.rb', line 22

def initial
  self[0, 1]
end

#number?Boolean

Returns:

  • (Boolean)


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

def number?
  true if Integer(self)
rescue StandardError
  false
end

#range_present?Boolean

Returns:

  • (Boolean)


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

def range_present?
  !empty?
end

#remove_trailing_numberObject



34
35
36
# File 'lib/utils.rb', line 34

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

#unquoteObject



26
27
28
# File 'lib/utils.rb', line 26

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