Class: AutoNic

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAutoNic

Returns a new instance of AutoNic.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/autonic.rb', line 8

def initialize
  @consonants = "bcdfghjklmnpqrstvwxyz"
  @vowels = "aeiou"

  @combos = []
  @consonants.each_char do |con|
    @vowels.each_char do |vow|
      @combos << con+vow
    end
  end
  @macaddr = Mac.addr
end

Instance Attribute Details

#macaddrObject

Returns the value of attribute macaddr.



6
7
8
# File 'lib/autonic.rb', line 6

def macaddr
  @macaddr
end

Instance Method Details

#cleanName(n) ⇒ Object



37
38
39
# File 'lib/autonic.rb', line 37

def cleanName(n)
  return n.gsub("- ", '-').gsub(" -", ' ').gsub("--", '-').strip().gsub(/-$/, '')
end

#macAddrToNameObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/autonic.rb', line 41

def macAddrToName
  name = " "
  x = @macaddr.gsub(/[-: ]/, '')
  while x.length > 0 do
    tup = popHexPair(x)
    n = tup[:num]
    syllable = ''
    if(n < @combos.length)
      syllable = @combos[n]
    else
      if (n/2 < @combos.length)
        if (n%3 == 0)
          syllable = @combos[n/2] + ' '
        elsif (n%2 == 0)
          syllable = @combos[n/2]
        end
      else
        syllable = ' '
      end
    end
    name = name + syllable
    x = tup[:rest]
  end
  sname = name.upcase.split /\s+/
  capname = sname.join(' ')
  return cleanName(capname)
end

#nameObject



21
22
23
# File 'lib/autonic.rb', line 21

def name
  macAddrToName.downcase.gsub(' ', '_')
end

#popHexPair(s) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/autonic.rb', line 25

def popHexPair(s)
  if s.length < 3
    num = s.to_i(16)
    rest = ""
  else
    num = s[0..1].to_i(16)
    rest = s[2..s.length]
  end
  return :num => num, :rest => rest
end