Class: Cloudrunpdf::Builder
- Inherits:
-
Object
- Object
- Cloudrunpdf::Builder
- Defined in:
- lib/cloudrunpdf/builder.rb
Instance Method Summary collapse
- #generate_pdf(data) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #print(data) ⇒ Object
- #provider ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
6 7 8 9 |
# File 'lib/cloudrunpdf/builder.rb', line 6 def initialize @configuration = Cloudrunpdf.configuration @provider = provider end |
Instance Method Details
#generate_pdf(data) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/cloudrunpdf/builder.rb', line 30 def generate_pdf(data) connection = @provider.connection connection.post(@configuration.cloud_function_url) do |req| req.body = data.to_json end end |
#print(data) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cloudrunpdf/builder.rb', line 11 def print(data) threads = [] data = [data] unless data.is_a?(Array) Thread.report_on_exception = false data.each do |entry| threads.append( Thread.new { Thread.current[:pdf] = generate_pdf(entry) } ) end threads.reduce(::CombinePDF.new) do |collector, thread| thread.join collector << ::CombinePDF.parse(thread[:pdf].body) end.to_pdf end |
#provider ⇒ Object
38 39 40 41 |
# File 'lib/cloudrunpdf/builder.rb', line 38 def provider klass = "Cloudrunpdf::Providers::#{@configuration.platform}" @provider ||= Object.const_get(klass).new(@configuration) end |