Module: Iroki::CoreExt::String

Defined in:
lib/iroki/core_ext/string/string.rb

Instance Method Summary collapse

Instance Method Details

#cleanObject



14
15
16
# File 'lib/iroki/core_ext/string/string.rb', line 14

def clean
  self.gsub(/'/, '"')
end

#clean_nameObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/iroki/core_ext/string/string.rb', line 26

def clean_name
  if (match = self.has_color?)
    name = match[1]
    color = match[2]

    name.single_quote + color
  else
    self.single_quote
  end
end

#clean_strictObject



37
38
39
# File 'lib/iroki/core_ext/string/string.rb', line 37

def clean_strict
  self.strip.gsub(/[^\p{Alnum}_]+/, "_").gsub(/_+/, "_")
end

#has_color?Boolean Also known as: already_checked?

Returns:

  • (Boolean)


5
6
7
# File 'lib/iroki/core_ext/string/string.rb', line 5

def has_color?
  self.match(/(.*)(\[&!color="#[0-9A-Fa-f]{6}"\])/)
end

#has_single_quote?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/iroki/core_ext/string/string.rb', line 41

def has_single_quote?
  self.match(/'/)
end

#hex?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/iroki/core_ext/string/string.rb', line 10

def hex?
  self.match(/^#[0-9A-Fa-f]{6}$/)
end

#single_quoteObject



18
19
20
21
22
23
24
# File 'lib/iroki/core_ext/string/string.rb', line 18

def single_quote
  if self.match /\A'.*'\Z/
    self.dup
  else
    %Q['#{self.clean}']
  end
end