Module: XmlSchemaMapper::ClassMethods
- Defined in:
- lib/xml_schema_mapper.rb
Instance Method Summary collapse
- #annonymus_type(name) ⇒ Object
- #attrs ⇒ Object
- #build_tree ⇒ Object
- #elements ⇒ Object
- #parse(string_or_node) ⇒ Object
- #schema(location = nil) ⇒ Object
- #type(name = nil) ⇒ Object
Instance Method Details
#annonymus_type(name) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/xml_schema_mapper.rb', line 46 def annonymus_type(name) raise(%Q{call "schema 'path/to/your/File.xsd'" before calling "type"}) unless _schema path = name.split('::') type = _schema.types[path.shift] self._type = path.map do |n| type = type.elements[n].type if type end.last end |
#attrs ⇒ Object
74 75 76 |
# File 'lib/xml_schema_mapper.rb', line 74 def attrs @attrs ||= type.attributes end |
#build_tree ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/xml_schema_mapper.rb', line 78 def build_tree instance = new self.elements.each do |e| instance[e.reader] = e.mapper_class.build_tree if e.complex? end instance end |
#elements ⇒ Object
68 69 70 71 72 |
# File 'lib/xml_schema_mapper.rb', line 68 def elements @elements ||= type.elements.values.map do |element| XmlSchemaMapper::Element.new(element) end end |
#parse(string_or_node) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/xml_schema_mapper.rb', line 55 def parse(string_or_node) return if string_or_node.nil? case string_or_node when String string = File.exist?(string_or_node) ? File.read(string_or_node) : string_or_node XmlSchemaMapper::Parser.new(self).parse(string) when Nokogiri::XML::Node XmlSchemaMapper::Parser.new(self).parse(string_or_node) else raise(ArgumentError, "param must be a String or Nokogiri::XML::Node, but \"#{string_or_node.inspect}\" given") end end |
#schema(location = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/xml_schema_mapper.rb', line 28 def schema(location=nil) if location self._schema = LibXML::XML::Schema.cached(location) else self._schema end end |
#type(name = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/xml_schema_mapper.rb', line 36 def type(name=nil) raise(%Q{call "schema 'path/to/your/File.xsd'" before calling "type"}) unless _schema if name self._type = _schema.types[name] attr_accessor :attrs else self._type end end |