Class: ODDB::Import::GkvHandler

Inherits:
Rpdf2txt::SimpleHandler
  • Object
show all
Defined in:
lib/oddb/import/gkv.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback) ⇒ GkvHandler

Returns a new instance of GkvHandler.



16
17
18
19
20
# File 'lib/oddb/import/gkv.rb', line 16

def initialize callback
  @callback = callback
  @rows = []
  reset
end

Instance Attribute Details

#pairsObject (readonly)

Returns the value of attribute pairs.



15
16
17
# File 'lib/oddb/import/gkv.rb', line 15

def pairs
  @pairs
end

Instance Method Details

#resetObject



21
22
23
# File 'lib/oddb/import/gkv.rb', line 21

def reset
  @current_line = ''
end

#send_flowing_data(data) ⇒ Object



24
25
26
# File 'lib/oddb/import/gkv.rb', line 24

def send_flowing_data(data)
  @current_line << data
end

#send_line_breakObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/oddb/import/gkv.rb', line 27

def send_line_break
  data = @current_line.strip.split /\s{3,}/
  if /^\d{6,}$/.match(data[1].to_s)
    ## ensure consistent row-length, so we can append additional substances
    #  to the tail
    data[9] ||= nil
    @rows.push data
  else
    @rows.push :doubtful
  end
  reset
end

#send_pageObject



39
40
41
42
43
# File 'lib/oddb/import/gkv.rb', line 39

def send_page
  @callback.call @rows
  @rows = []
  reset
end