Class: ESBify::Expectation

Inherits:
Base
  • Object
show all
Defined in:
lib/ESBify/expectation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_xml_partial

Constructor Details

This class inherits a constructor from ESBify::Base

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



4
5
6
# File 'lib/ESBify/expectation.rb', line 4

def names
  @names
end

Instance Method Details

#<<(sects) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/ESBify/expectation.rb', line 25

def <<(sects)
  @names ||= []
  @data += sects.map do |sect|
    sect["rho_plus"] = parse_mods(sect["rho_plus"]) if sect["rho_plus"]
    sect["rho_minus"] = parse_mods(sect["rho_minus"]) if sect["rho_minus"]
    @names << sect["name"] if sect["name"]
    defaults.merge(sect)
  end
end

#defaultsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ESBify/expectation.rb', line 6

def defaults
  {
    "agent" => "self",
    "name" => rand(1000),
    "condition" => "true",
    "phi" => "",
    "test_plus" => "",
    "test_minus" => "",
    "rho_plus" => {
      "addSet" => [],
      "remSet" => []
    },
    "rho_minus" => {
      "addSet" => [],
      "remSet" => []
    }
  }
end

#parse_mods(str) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ESBify/expectation.rb', line 35

def parse_mods(str)
  add_set = []
  rem_set = []
  str.scan(/^\s*(\+|\-)\s*(.+)\s*$/).each do |sym, str|
    if sym == "+"
      add_set << str
    else
      rem_set << str
    end
  end
  {"addSet" => add_set, "remSet" => rem_set}
end

#to_xmlObject



48
49
50
51
52
53
54
55
# File 'lib/ESBify/expectation.rb', line 48

def to_xml
  b = Builder::XmlMarkup.new indent: 2
  b.instruct!
  b.declare! :DOCTYPE, :ExpectationSet, :SYSTEM, "esb-ji-jason/ExpectationSet.dtd"
  b.ExpectationSet do |b|
    b << to_xml_partial
  end # ExpectationSet
end

#xml_section(b, sect) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ESBify/expectation.rb', line 57

def xml_section(b, sect)
  b.tag! "expectation" do |b|
    sect.each do |k,v|
      if v.is_a?(Array) || v.is_a?(Hash)
        b.tag! k do |b|
          b.tag! "addSet" do |b|
            v["addSet"].each {|el| b.name(el) }
          end
          b.tag! "remSet" do |b|
            v["remSet"].each {|el| b.name(el) }
          end
        end 
      else
        b.tag! k, v
      end
    end
  end # base
end