Class: Wurfl::Command::Comparator

Inherits:
Wurfl::Command show all
Includes:
Utils
Defined in:
lib/wurfl/command/comparator.rb

Instance Method Summary collapse

Methods included from Utils

#load_wurfl_pstore, #save_wurfl_pstore

Instance Method Details

#display_differences(hand1, hand2) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wurfl/command/comparator.rb', line 14

def display_differences(hand1, hand2)
  puts "-------------------------------------"
  puts "WURFL_ID: #{hand1.wurfl_id}" 
  puts "Handset 1: #{hand1.user_agent}"
  puts "Handset 2: #{hand2.user_agent}"
  hand1.differences(hand2).each do |key|
    v1, v2 = hand1[key], hand2[key]
    puts "Key:#{key}"
    puts "h1>:#{hand1[key]}"
    puts "h2<:#{hand2[key]}"
  end
  puts "-------------------------------------"
end

#executeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
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
68
69
70
# File 'lib/wurfl/command/comparator.rb', line 28

def execute
  if ARGV.size != 2
    usage
  end

  # load the wurfl databases
  wurfl1 = wurfl2 = nil
  begin
    wurfl1 = load_wurfl_pstore(ARGV[0])
    wurfl2 = load_wurfl_pstore(ARGV[1])
  rescue => err
    efile = ""
    if wurfl1.nil?
      efile = ARGV[0]
    else
      efile = ARGV[1]
    end
    STDERR.puts "Error with file #{efile}"
    STDERR.puts err.message
    exit 1
  end

  puts "Comparing files: #{ARGV[0]} and #{ARGV[1]}"
  puts "-------------------------------------"

  wurfl1_unknown, wurfl2_unknown, different = [],[],[]
  (wurfl1.keys | wurfl2.keys).each do |key|
    handset1, handset2 = wurfl1[key], wurfl2[key]
    if !handset1
      wurfl1_unknown << key
    elsif !handset2
      wurfl2_unknown << key
    elsif handset1 != handset2
      display_differences(handset1,handset2)
    end
  end


  puts "Comparision complete."

  puts "Handsets not found in wurfl1: #{wurfl1_unknown.inspect}"
  puts "Handsets not found in wurfl2: #{wurfl2_unknown.inspect}"
end

#usageObject



9
10
11
12
# File 'lib/wurfl/command/comparator.rb', line 9

def usage
  puts "Usage: wurfltools.rb comparator wurfl_pstore1_db wurfl_pstore2_db  "
  exit 1
end