Class: Soap::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/soap/parser.rb

Constant Summary collapse

COMMON_ATTRIBUTES =
%i[input output].freeze
DEFAULT_SECTIONS =
%w[types message port_type binding service].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Parse

Returns a new instance of Parse.



11
12
13
# File 'lib/soap/parser.rb', line 11

def initialize(file)
  @document = Nokogiri::XML(file)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



9
10
11
# File 'lib/soap/parser.rb', line 9

def document
  @document
end

Instance Method Details

#extract_types_attribute(name, io) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/soap/parser.rb', line 48

def extract_types_attribute(name, io)
  msg_name = port_type[name][io][:message].split(":").last
  components = binding[:operations][name][io]
  ext = {}
  components.map do |k, v|
    component = message[msg_name][:part]
    if v[:part].nil? && v[:parts].nil?
      namespace, params = component.values.first.split(":")
    else
      namespace, params = component[v[:part] || v[:parts]].split(":")
    end
    ext[k.to_sym] = types[namespace][params][:params]
  end
  ext
end

#namespacesObject



15
16
17
18
19
20
# File 'lib/soap/parser.rb', line 15

def namespaces
  @namespaces = @document.namespaces.inject({}) do |memo, (key, value)|
    memo[key.sub("xmlns:", "")] = value
    memo
  end
end

#section(section_name) ⇒ Object



64
65
66
# File 'lib/soap/parser.rb', line 64

def section(section_name)
  sections[section_name] || []
end

#sectionsObject



68
69
70
71
72
73
# File 'lib/soap/parser.rb', line 68

def sections
  @sections ||=
    @document.root.element_children.each.with_object({}) do |node, attrs|
      (attrs[Soap.to_snakecase(node.name)] ||= []) << node
    end
end

#soap_action(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/soap/parser.rb', line 37

def soap_action(name)
  Soap::Parse::COMMON_ATTRIBUTES.each.with_object({}) do |common, attrs|
    attrs[common] = {
      port_type: port_type[name][common],
      binding: binding[:operations][name][common],
      message: message[port_type[name][common][:message].split(":").last],
      types: extract_types_attribute(name, common)
    }
  end
end

#soap_actionsObject



31
32
33
34
35
# File 'lib/soap/parser.rb', line 31

def soap_actions
  port_type.keys.map do |pt|
    pt
  end
end