Class: Barcoder::PDF
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#messages ⇒ Object
Messages is an array of barcoded messages that are encoded onto each page as a barcode.
-
#missing_pages_count ⇒ Object
Returns the value of attribute missing_pages_count.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#pdf_content ⇒ Object
Returns the value of attribute pdf_content.
-
#token ⇒ Object
Returns the value of attribute token.
-
#total_pages_count ⇒ Object
Returns the value of attribute total_pages_count.
Class Method Summary collapse
- .barcode_uri ⇒ Object
- .decode_from_file(bucket, filename) ⇒ Object
- .decode_from_string(bucket, string) ⇒ Object
- .decode_uri ⇒ Object
- .get(bucket, id) ⇒ Object
- .new_from_file(filename, attr = {}) ⇒ Object
Instance Method Summary collapse
-
#barcode! ⇒ Object
Send file to be barcoded.
-
#queue_barcode ⇒ Object
Queues the barcode request on hydra.
-
#write_to_file(filename) ⇒ Object
Writes PDF content to filename TODO: test.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Barcoder::Base
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def bucket @bucket end |
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def id @id end |
#messages ⇒ Object
Messages is an array of barcoded messages that are encoded onto each page as a barcode.
45 46 47 |
# File 'lib/barcoder/pdf.rb', line 45 def @messages end |
#missing_pages_count ⇒ Object
Returns the value of attribute missing_pages_count.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def missing_pages_count @missing_pages_count end |
#pages ⇒ Object
Returns the value of attribute pages.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def pages @pages end |
#pdf_content ⇒ Object
Returns the value of attribute pdf_content.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def pdf_content @pdf_content end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def token @token end |
#total_pages_count ⇒ Object
Returns the value of attribute total_pages_count.
3 4 5 |
# File 'lib/barcoder/pdf.rb', line 3 def total_pages_count @total_pages_count end |
Class Method Details
.barcode_uri ⇒ Object
8 9 10 |
# File 'lib/barcoder/pdf.rb', line 8 def self. "#{Barcoder::Config.host}/barcode" end |
.decode_from_file(bucket, filename) ⇒ Object
26 27 28 |
# File 'lib/barcoder/pdf.rb', line 26 def self.decode_from_file(bucket, filename) decode_from_string(bucket, File.read(filename)) end |
.decode_from_string(bucket, string) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/barcoder/pdf.rb', line 30 def self.decode_from_string(bucket, string) encoded = Base64.encode64(string) opt = {body: {pdf_content: encoded, token: bucket.token}, method: :post} response = Typhoeus::Request.new(decode_uri, opt).run response.success? end |
.decode_uri ⇒ Object
12 13 14 |
# File 'lib/barcoder/pdf.rb', line 12 def self.decode_uri "#{Barcoder::Config.host}/decode" end |
Instance Method Details
#barcode! ⇒ Object
Send file to be barcoded.
Updates pdf_content
with the barcoded version of the PDF.
56 57 58 59 60 61 62 |
# File 'lib/barcoder/pdf.rb', line 56 def return false unless valid? .run true end |
#queue_barcode ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/barcoder/pdf.rb', line 68 def return false unless valid? Barcoder::Config.hydra.queue true end |
#write_to_file(filename) ⇒ Object
Writes PDF content to filename TODO: test
78 79 80 81 82 83 |
# File 'lib/barcoder/pdf.rb', line 78 def write_to_file(filename) f = File.new(filename, 'w', encoding: 'ascii-8bit') f.write pdf_content f.close true end |