Class: Conflict::RequestParser

Inherits:
Object
  • Object
show all
Defined in:
lib/conflict/parsers.rb

Instance Method Summary collapse

Constructor Details

#initialize(ttl) ⇒ RequestParser

Returns a new instance of RequestParser.

Raises:



22
23
24
25
26
# File 'lib/conflict/parsers.rb', line 22

def initialize ttl
  raise ConflictException::new("ttl cannot be nil") if nil.eql?(ttl)
  raise ConflictException::new("ttl cannot be negative") if ttl < 0
  @ttl = ttl
end

Instance Method Details

#parse(diff, info, client) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/conflict/parsers.rb', line 28

def parse diff, info, client
  
  events = []

  for i in 0..diff.list.size - 1
      
    diff_data = diff.list[i].to_s.strip
    info_data = info.list[i].to_s.strip
      
    raise "no value for info @ index " + i.to_s if info_data.nil? or info_data.empty?
    
    lambda {
      infos = InfoParser::new().parse(info_data)
      events = events | DiffParser::new(infos.merge({:ttl=>@ttl})).parse(diff_data, client, infos[:url], infos[:path])
    }.call if ! diff_data.nil? && ! diff_data.empty?
    
  end
  
  events
  
end

#parse_cvs(diffs, client) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/conflict/parsers.rb', line 50

def parse_cvs diffs, client

  events = []

  diffs.each do | diff |

    d = diff.to_s.strip
    lambda{
      events = events | DiffParser::new({:ttl=>@ttl}).parse_cvs(d, client)
    }.call if ! d.nil? && ! d.empty?

  end

  events

end