Class: Richard::CurlReply

Inherits:
Object
  • Object
show all
Defined in:
lib/richard_iii/curl_reply.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ CurlReply

Returns a new instance of CurlReply.



5
6
7
8
9
# File 'lib/richard_iii/curl_reply.rb', line 5

def initialize(text)
  @text = text
  @missing = @surplus = []
  @pretty = false
end

Instance Attribute Details

#missingObject (readonly)

Returns the value of attribute missing.



3
4
5
# File 'lib/richard_iii/curl_reply.rb', line 3

def missing
  @missing
end

#surplusObject (readonly)

Returns the value of attribute surplus.



3
4
5
# File 'lib/richard_iii/curl_reply.rb', line 3

def surplus
  @surplus
end

Instance Method Details

#==(text) ⇒ Object



39
# File 'lib/richard_iii/curl_reply.rb', line 39

def ==(text); self.eql? text; end

#eql?(text) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/richard_iii/curl_reply.rb', line 34

def eql?(text)
  strip(@text).eql? strip(text)
end

#equals?(text) ⇒ Boolean

Returns:

  • (Boolean)


38
# File 'lib/richard_iii/curl_reply.rb', line 38

def equals?(text); self.eql? text; end

#inspectObject



42
# File 'lib/richard_iii/curl_reply.rb', line 42

def inspect; to_s; end

#matches?(expected) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/richard_iii/curl_reply.rb', line 15

def matches?(expected)
  actual_lines   = strip(@text)
  
  expected_lines = parse(expected)
   
  matches = actual_lines.select do |line|
    expected_lines.any?{|it| it.matches?(line)}
  end

  expectations_that_did_not_match_anything = expected_lines.select do |expected|
    actual_lines.none?{|line| expected.matches?(line)}
  end

  @missing = expectations_that_did_not_match_anything.map(&:text)
  @surplus = actual_lines - matches

  return matches.size.eql? expected_lines.size
end

#to_sObject



41
# File 'lib/richard_iii/curl_reply.rb', line 41

def to_s; @text; end

#use_pretty_xmlObject



11
12
13
# File 'lib/richard_iii/curl_reply.rb', line 11

def use_pretty_xml
  @pretty = true;
end