class FiasParser::Document

Public Class Methods

new( options, block ) click to toggle source
# File lib/fias_parser.rb, line 8
def initialize( options, block )
  @block = block
  @batch = []
  @batch_size = options[:batch_size] || 10
  
  @root_name = nil
  @item_name = nil
end

Public Instance Methods

attr( name, value ) click to toggle source
# File lib/fias_parser.rb, line 30
def attr( name, value )
  @item[ name ] = value unless @item.nil?
end
end_element( name ) click to toggle source
# File lib/fias_parser.rb, line 34
def end_element( name )
  self.yield_batch if name == @root_name && @batch.any?

  return if @item.nil? || name != @item_name
  
  @batch << @item

  self.yield_batch if @batch.size >= @batch_size
end
start_element( name ) click to toggle source
# File lib/fias_parser.rb, line 17
def start_element( name )
  @item = nil

  if @root_name.nil?
    @root_name = name
    
    return
  end
  
  @item_name = name
  @item = {}
end
yield_batch() click to toggle source
# File lib/fias_parser.rb, line 44
def yield_batch
  @block.call( @batch )      
  @batch = []      
end