Class: ROGC::Formats::XML::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rogc/formats/xml/base.rb

Direct Known Subclasses

VersionedOGC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



38
39
40
41
42
43
44
45
46
# File 'lib/rogc/formats/xml/base.rb', line 38

def initialize
  # @io = io
  # @parser = LibXML::XML::Parser.io(io)
  # @raw = @parser.parse
  # @capabilities = OpenStruct.new
  # @root = @raw.root
  # self.class.read_node(@root, @capabilities)
  @xml_readers = {}
end

Instance Attribute Details

#xml_readersObject

Returns the value of attribute xml_readers.



36
37
38
# File 'lib/rogc/formats/xml/base.rb', line 36

def xml_readers
  @xml_readers
end

Instance Method Details

#child_value(node, default = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rogc/formats/xml/base.rb', line 77

def child_value(node, default = nil)
  value = default || ""
      
  node.each do |child|
    case child.node_type
    when 3,4 # Text: 3 or CDATA: 4 use cdata? or text?
      value << child.content
    end
  end
  value.strip!
      
  value
end

#read_child_nodes(node, obj) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rogc/formats/xml/base.rb', line 62

def read_child_nodes(node, obj)
  if (obj.nil?)
    obj = OpenStruct.new
  end
      
  children = node.children
  children.each do |child|
    if (child.node_type == 1)
      read_node(child, obj)
    end
  end
      
  obj
end

#read_node(node, obj) ⇒ Object

class << self



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rogc/formats/xml/base.rb', line 49

def read_node(node, obj)
  if (obj.nil?)
    obj = OpenStruct.new
  end
      
  # reader = self.readers['wms'][node.name]
  reader = xml_readers['wms'][node.name]
  if (reader)
    reader.call(node, obj)
  end
  obj
end