Class: String

Inherits:
Object show all
Defined in:
lib/infra/ospf_common.rb

Instance Method Summary collapse

Instance Method Details

#hexlifyObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/infra/ospf_common.rb', line 58

def hexlify
  l,n,ls,s=0,0,[''],self.dup
  while s.size>0
    l = s.slice!(0,16)
    ls << format("0x%4.4x:  %s", n, l.unpack("n#{l.size/2}").collect { |x| format("%4.4x",x) }.join(' '))
    n+=1
  end
  if l.size%2 >0
    ns = if l.size>1 then 1 else 0 end
    ls.last << format("%s%2.2x",' '*ns,l[-1])
  end
  ls
end

#to_camelObject



54
55
56
# File 'lib/infra/ospf_common.rb', line 54

def to_camel
  split('_').collect {|x| x.capitalize}.join
end

#to_underscoreObject



50
51
52
# File 'lib/infra/ospf_common.rb', line 50

def to_underscore
  gsub(/([A-Z]+|[A-Z][a-z])/) {|x| ' ' + x }.gsub(/[A-Z][a-z]+/) {|x| ' ' + x }.split.collect{|x| x.downcase}.join('_')
end