Module: Iroki::CoreExt::String

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

Instance Method Summary collapse

Instance Method Details

#cleanObject



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

def clean
  # puts %Q{clean: #{self}, #{self.gsub(/'/, '"')}}
  self.gsub(/'/, '"')
end

#clean_nameObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/iroki/core_ext/string/string.rb', line 29

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

    # puts %Q{clean_name if: #{self}, returning #{name.single_quote + color}}
    name.single_quote + color
    # name + color
  else
    # puts %Q{clean_name else: #{self}, returning #{self.single_quote}}
    self.single_quote
  end
end

#clean_strictObject



43
44
45
# File 'lib/iroki/core_ext/string/string.rb', line 43

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)


48
49
50
# File 'lib/iroki/core_ext/string/string.rb', line 48

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



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

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