8
9
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/wayback/response/parse_memento.rb', line 8
def parse(body, *opts)
case body
when /^\<http/
body, info = body.gsub(/,(\s+)?\</, ",\n<").gsub(/\s(\s+)/, ' ').split("\n"), {:id => nil, :dates => {}, :first_date => nil, :last_date => nil}
body.each do |s|
attrs, uri = s.split('; '), s.gsub(/^(\<)([A-Z0-9\-\/\:\.\?\=\&]+)(\>)(.*)$/i, '\2')
rels, datetime, date, from, til = [], nil, nil, nil, nil
attrs.each do |a|
k, v = a.gsub(/^([A-Z0-9\-]+)(=.*)$/i, '\1'), a.gsub(/^([A-Z0-9\-]+)(=(\'|\"))(.*)(\'|\")(,)?$/i, '\4')
case k
when 'datetime'
datetime, date = v, Time.parse(v).utc.strftime('%Y%m%d%H%M%S').to_i
when 'rel'
rels = v.split(' ')
when 'from'
when 'until'
end
end
if rels.include?('original')
info[:id] = uri
elsif rels.include?('memento')
info[:last_date] = date if rels.include?('last')
info[:first_date] = date if rels.include?('first')
info[:dates][date] = {:datetime => datetime, :uri => uri} unless date.nil?
elsif rels.include?('timebundle')
elsif rels.include?('timegate')
elsif rels.include?('timemap')
end
end
info
else
nil
end
end
|