10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/browscapper/reader/ini_reader.rb', line 10
def load(file)
ini = IniFile.load(file, :encoding => 'BINARY')
entries = {
browscap_version: ini['GJK_Browscap_Version'].each_with_object({}) { |(k, v), memo|
memo[k.downcase.to_sym] = v
}
}
ini.delete_section('GJK_Browscap_Version')
injector = proc { |memo, section|
unless memo[section]
entry = UserAgent.new
ini[section].each do |k, v|
entry[k] = case v
when 'false'
false
when 'true'
true
when /^\d+$/
v.to_i
else
v
end
end
entry.user_agent = section
entry.pattern = pattern_to_regexp(entry.user_agent)
memo[section] = entry
if entry.parent
memo = injector.call(memo, entry.parent)
entry.merge!(memo[entry.parent])
end
end
memo
}
ini.sections.inject(entries, &injector)
end
|