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

#initializeCallbackHandler

Returns 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

#pairsObject (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

#column_widthObject



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

def column_width
  1
end

#firstword(str) ⇒ Object



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

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

#identify_columns?Boolean

Returns:

  • (Boolean)


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

def identify_columns?
  true
end

#resetObject



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

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

#send_columnObject



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

#send_flowing_data(data) ⇒ Object



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

#send_line_breakObject



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

#send_pageObject



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

def send_page
	reset
end