Class: String

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

Constant Summary collapse

BLANK_RE =
/\A[[:space:]]*\z/

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/core_ext.rb', line 4

def blank?
  empty? || BLANK_RE === self || self == "\u001A"
end

#delete_surrounding(char) ⇒ Object



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

def delete_surrounding(char)
  self.delete_prefix(char).delete_suffix(char)
end

#enquoteObject



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

def enquote
  "\"#{to_s}\""
end

#indent(spaces = 2) ⇒ Object



8
9
10
# File 'lib/core_ext.rb', line 8

def indent(spaces = 2)
  lines.map { |line| " " * spaces + line }.join
end

#inline_dcmObject



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

def inline_dcm
  "KONSERVIERUNG_FORMAT 2.0\n\n" + self
end

#to_regexp(ignorecase: false, multiline: false, extended: false) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/core_ext.rb', line 28

def to_regexp(ignorecase: false, multiline: false, extended: false)
  options = 0
  options = options | Regexp::EXTENDED   if extended
  options = options | Regexp::IGNORECASE if ignorecase
  options = options | Regexp::MULTILINE  if multiline
  Regexp.new(self, options)
end

#to_siObject



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

def to_si
  [self].pack("H*").unpack("l>").first
end