Class: ODDB::CoMarketing::PdfParser::CallbackHandler
- Inherits:
-
Rpdf2txt::SimpleHandler
- Object
- Rpdf2txt::SimpleHandler
- ODDB::CoMarketing::PdfParser::CallbackHandler
- Defined in:
- ext/comarketing/src/pdf_parser.rb
Instance Attribute Summary collapse
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
Instance Method Summary collapse
- #column_width ⇒ Object
- #firstword(str) ⇒ Object
- #identify_columns? ⇒ Boolean
-
#initialize ⇒ CallbackHandler
constructor
A new instance of CallbackHandler.
- #reset ⇒ Object
- #send_column ⇒ Object
- #send_flowing_data(data) ⇒ Object
- #send_line_break ⇒ Object
- #send_page ⇒ Object
Constructor Details
#initialize ⇒ CallbackHandler
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
#pairs ⇒ Object (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_width ⇒ Object
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
22 23 24 |
# File 'ext/comarketing/src/pdf_parser.rb', line 22 def identify_columns? true end |
#reset ⇒ Object
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_column ⇒ Object
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_break ⇒ Object
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_page ⇒ Object
53 54 55 |
# File 'ext/comarketing/src/pdf_parser.rb', line 53 def send_page reset end |