Class: LibertyBot::Prefix

Inherits:
String
  • Object
show all
Defined in:
lib/libertybot/prefix.rb

Instance Method Summary collapse

Instance Method Details

#extractObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/libertybot/prefix.rb', line 26

def extract
  nick, user, host = [ nil ] * 3
  
  user_offset = self.index ?!
  
  host_offset = self.index ?@
  host_offset = user_offset + self[(user_offset)..-1].index(?@) if user_offset && self[(user_offset)..-1].index(?@)
  
  host = self[(host_offset + 1)..-1] if host_offset
  nick = self[0..(user_offset - 1)] if user_offset
  
  if user_offset && host_offset
    user = self[(user_offset + 1)..(host_offset - 1)]
  elsif host_offset
    nick = self[0..(host_offset - 1)]
  elsif user_offset
    user = self[(user_offset + 1)..-1]
  else
    nick = self
  end
  
  [ nick, user, host ]
end

#hostObject



58
59
60
# File 'lib/libertybot/prefix.rb', line 58

def host
  extract[2]
end

#nickObject



50
51
52
# File 'lib/libertybot/prefix.rb', line 50

def nick
  extract[0]
end

#userObject



54
55
56
# File 'lib/libertybot/prefix.rb', line 54

def user
  extract[1]
end