Class: RETS4R::Client::Metadata::CompactDocument

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/rets4r/client/parsers/metadata.rb

Overview

Nokogiri SAX compact metadata parser

Constant Summary collapse

DELIMITER =
"\t"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCompactDocument

Returns a new instance of CompactDocument.



107
108
109
# File 'lib/rets4r/client/parsers/metadata.rb', line 107

def initialize
  @parser = Nokogiri::XML::SAX::Parser.new(self)
end

Class Method Details

.parse_file(filename) ⇒ Object



103
104
105
# File 'lib/rets4r/client/parsers/metadata.rb', line 103

def self.parse_file(filename)
  new.parse_file(filename)
end

Instance Method Details

#characters(content) ⇒ Object



157
158
159
# File 'lib/rets4r/client/parsers/metadata.rb', line 157

def characters content
  @current_content << content if receives_content? @stack.last[0]
end

#end_element(name) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rets4r/client/parsers/metadata.rb', line 139

def end_element name
  case name.upcase
  when 'DATA'
    process_content_as_data
  when 'COLUMNS'
    process_content_as_columns
  when 'SYSTEM'
    # unlike the other tags here, SYSTEM cotains its own content so it
    # needs to be processed as well as removed from the stack.
    process_content_as_system
    @stack.pop
  when 'COMMENTS'
    process_content_as_comments
  else
    @stack.pop
  end
end

#parse(content) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/rets4r/client/parsers/metadata.rb', line 115

def parse(content)
  @metadata = Metadata.new
  @stack    = []
  @current_content = ''
  @parser.parse(content)
  @metadata
end

#parse_file(filename = 'metadata.xml') ⇒ Object



111
112
113
# File 'lib/rets4r/client/parsers/metadata.rb', line 111

def parse_file(filename = 'metadata.xml')
  parse(File.open(filename))
end

#start_element(name, raw_attrs = []) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rets4r/client/parsers/metadata.rb', line 123

def start_element name, raw_attrs = []
  attrs = Hash[*raw_attrs.flatten]

  case name.upcase
  when 'DATA'
    @current_content = ''
  when 'COLUMNS'
    @current_content = ''
    @columns = []
  when 'COMMENTS'
    @current_content = ''
  else
    @stack << [name.upcase, attrs]
  end
end