module I2PLookuper::SAMHelper

Public Class Methods

parsesamcmd(ans) click to toggle source
# File lib/i2plookuper.rb, line 23
def self.parsesamcmd ans
  ans.chomp!
  ans += " "
  f = ans.index " "
  s = ans.index " ", f + 1
  w = ans[f+1...s]

  args = Hash.new
  loop do
    g1 = ans.index "=", s+1
    break if g1 == nil
    g2 = nil
    if ans[g1+1] == "\""
      g2 = ans.index "\"", g1+2
      args[ans[s+1..g1-1]] = ans[g1+2..g2-1]
    else
      g2 = ans.index " ", g1+1
      args[ans[s+1..g1-1]] = ans[g1+1..g2-1]
    end
    s = g2
  end

  return [ans[0...f], w, args]
end
samcmd(fircmd, seccmd = nil, args = {}) click to toggle source
# File lib/i2plookuper.rb, line 15
def self.samcmd fircmd, seccmd = nil, args = {}
  cmd = "#{fircmd}#{seccmd ? " #{seccmd}" : ""}"
  args.each_pair { |arg, value|
    cmd << " #{arg}=\"#{value.to_s}\""
  }
  return cmd
end