Module: WADL::XMLRepresentation

Defined in:
lib/wadl/xml_representation.rb

Overview

A module mixed in to REXML documents to make them representations in the WADL sense.

Instance Method Summary collapse

Instance Method Details

#each_by_param(param_name) ⇒ Object

Yields up each XML element for the given Param object.



52
53
54
# File 'lib/wadl/xml_representation.rb', line 52

def each_by_param(param_name)
  REXML::XPath.each(self, lookup_param(param_name).path) { |e| yield e }
end

#get_by_param(param_name) ⇒ Object

Returns an XML element for the given Param object.



57
58
59
# File 'lib/wadl/xml_representation.rb', line 57

def get_by_param(param_name)
  REXML::XPath.first(self, lookup_param(param_name).path)
end

#lookup_param(name) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
# File 'lib/wadl/xml_representation.rb', line 42

def lookup_param(name)
  param = @params.find { |p| p.name == name }

  raise ArgumentError, "No such param #{name}" unless param
  raise ArgumentError, "Param #{name} has no path!" unless param.path

  param
end

#representation_of(format) ⇒ Object



38
39
40
# File 'lib/wadl/xml_representation.rb', line 38

def representation_of(format)
  @params = format.params
end