Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/knife-cosmic/connection.rb

Instance Method Summary collapse

Instance Method Details

#is_uuid?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/knife-cosmic/connection.rb', line 46

def is_uuid?
  self.strip =~ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/ ? true : false
end

#to_regexpObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/knife-cosmic/connection.rb', line 34

def to_regexp
  return nil unless self.strip.match(/\A\/(.*)\/(.*)\Z/mx)
  regexp , flags = $1 , $2
  return nil if !regexp || flags =~ /[^xim]/m

  x = /x/.match(flags) && Regexp::EXTENDED
  i = /i/.match(flags) && Regexp::IGNORECASE
  m = /m/.match(flags) && Regexp::MULTILINE

  Regexp.new regexp , [x,i,m].inject(0){|a,f| f ? a+f : a }
end