class Wurfl::Command::Inspector
Public Instance Methods
execute()
click to toggle source
# File lib/wurfl/command/inspector.rb, line 60 def execute pstorefile = nil procstr = nil handset = nil query = nil begin opt = GetoptLong.new( ["-d","--database", GetoptLong::REQUIRED_ARGUMENT], ["-s","--search", GetoptLong::REQUIRED_ARGUMENT], ["-i","--id", GetoptLong::REQUIRED_ARGUMENT], ["-q","--query", GetoptLong::REQUIRED_ARGUMENT] ) opt.each do |arg,val| case arg when "-d" pstorefile = val when "-s" procstr = val.strip when "-i" handset = val when "-q" query = val else usage end end rescue => err usage end if !pstorefile puts "You must specify a Wurfl PStore db" usage end begin handsets = load_wurfl_pstore(pstorefile) insp = WurflInspector.new(handsets) rescue => err STDERR.puts "Error with file #{pstorefile}" STDERR.puts err.message exit 1 end if procstr pr = nil eval("pr = proc#{procstr}") if pr.class != Proc STDERR.puts "You must pass a valid ruby block!" exit 1 end STDERR.puts "--------- Searching handsets -----------" res = insp.search_handsets(pr) STDERR.puts "Number of results: #{res.size}" res.each { |handset| puts handset.wurfl_id } exit 0 end if handset handset = insp.get_handset(handset) unless handset puts "No handset found" exit 1 end puts "Handset user agent: #{handset.user_agent}" if query puts "Result of handset query: #{query}" puts "#{handset[query]} from #{handset.owner(query)}" else puts "Attributes of handset" keys = handset.keys keys.each do |key| puts "Attr:#{key} Val:#{handset[key]} from #{handset.owner(key)}" end end exit 0 end end
usage()
click to toggle source
# File lib/wurfl/command/inspector.rb, line 51 def usage puts "Usage: wurfltools.rb inspector [-s rubyblock] [-i handsetid [-q attributename]] -d pstorefile" puts "Examples:" puts "wurfltools.rb inspector -d pstorehandsets.db -s '{ |hand| hand[\"colors\"].to_i > 2 }'" puts "wurfltools inspector -d pstorehandsets.db -i sonyericsson_t300_ver1" puts "wurfltools inspector -d pstorehandsets.db -i sonyericsson_t300_ver1 -q backlight" exit 1 end