Class: ODDB::CoMarketing::PdfParser::CallbackHandler

Inherits:
Rpdf2txt::SimpleHandler
  • Object
show all
Defined in:
ext/comarketing/src/pdf_parser.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CallbackHandler) initialize

A new instance of CallbackHandler



12
13
14
15
# File 'ext/comarketing/src/pdf_parser.rb', line 12

def initialize
  @pairs = []
  reset
end

Instance Attribute Details

- (Object) pairs (readonly)

Returns the value of attribute pairs



11
12
13
# File 'ext/comarketing/src/pdf_parser.rb', line 11

def pairs
  @pairs
end

Instance Method Details

- (Object) column_width



16
17
18
# File 'ext/comarketing/src/pdf_parser.rb', line 16

def column_width
  1
end

- (Object) firstword(str)



19
20
21
# File 'ext/comarketing/src/pdf_parser.rb', line 19

def firstword(str)
  str.strip.split(/\s+/u, 2).first
end

- (Boolean) identify_columns?

Returns:

  • (Boolean)


22
23
24
# File 'ext/comarketing/src/pdf_parser.rb', line 22

def identify_columns?
  true
end

- (Object) reset



25
26
27
28
29
# File 'ext/comarketing/src/pdf_parser.rb', line 25

def reset
  @current_column = 0
  @raw_original = ''
  @raw_comarketing = ''
end

- (Object) send_column



30
31
32
33
34
35
# File 'ext/comarketing/src/pdf_parser.rb', line 30

def send_column
  if(@current_column == 2 && firstword(@raw_original))
    @original = @raw_original[/\d{5}/u]
  end
  @current_column += 1
end

- (Object) send_flowing_data(data)



36
37
38
39
40
41
42
43
44
45
46
# File 'ext/comarketing/src/pdf_parser.rb', line 36

def send_flowing_data(data)
  if(match = /tierarzneimittel/iu.match(data))
    throw :vet_products
  end
  case @current_column
  when 1,2
    @raw_original << data
  when 4,5
    @raw_comarketing << data
  end
end

- (Object) send_line_break



47
48
49
50
51
52
# File 'ext/comarketing/src/pdf_parser.rb', line 47

def send_line_break
  if(@original && (iksnr = @raw_comarketing[/\d{5}/u]))
    @pairs.push([@original, iksnr])
  end
  reset
end

- (Object) send_page



53
54
55
# File 'ext/comarketing/src/pdf_parser.rb', line 53

def send_page
  reset
end