Class: PrintNode::PrintJob
- Inherits:
-
Object
- Object
- PrintNode::PrintJob
- Defined in:
- lib/printnode/printjob.rb
Overview
An object for printjob creation.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#printer_id ⇒ Object
Returns the value of attribute printer_id.
-
#source ⇒ Object
Returns the value of attribute source.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #content_is_existing_file? ⇒ Boolean
-
#initialize(printer_id, title, content_type, content, source) ⇒ PrintJob
constructor
Initializes the object with the variables required.
- #load_content ⇒ Object
-
#to_hash ⇒ Object
Maps the object into a hash ready for JSON Encoding.
Constructor Details
#initialize(printer_id, title, content_type, content, source) ⇒ PrintJob
Initializes the object with the variables required.
15 16 17 18 19 20 21 |
# File 'lib/printnode/printjob.rb', line 15 def initialize(printer_id, title, content_type, content, source) @printer_id = printer_id @title = title @content_type = content_type @content = content @source = source end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
11 12 13 |
# File 'lib/printnode/printjob.rb', line 11 def content @content end |
#content_type ⇒ Object
Returns the value of attribute content_type.
10 11 12 |
# File 'lib/printnode/printjob.rb', line 10 def content_type @content_type end |
#printer_id ⇒ Object
Returns the value of attribute printer_id.
8 9 10 |
# File 'lib/printnode/printjob.rb', line 8 def printer_id @printer_id end |
#source ⇒ Object
Returns the value of attribute source.
12 13 14 |
# File 'lib/printnode/printjob.rb', line 12 def source @source end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/printnode/printjob.rb', line 9 def title @title end |
Instance Method Details
#content_is_existing_file? ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/printnode/printjob.rb', line 45 def content_is_existing_file? begin File.exist?(@content) rescue false end end |
#load_content ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/printnode/printjob.rb', line 34 def load_content # Used to be, we only supported file names for Base64, but it's actually better # to allow the user to send us a data string if they desire. Testing the # content to see if it's a path allows for backwards compatibility if @content_type.match('base64$') && content_is_existing_file? Base64.encode64(IO.read(@content)) else @content end end |
#to_hash ⇒ Object
Maps the object into a hash ready for JSON Encoding.
24 25 26 27 28 29 30 31 32 |
# File 'lib/printnode/printjob.rb', line 24 def to_hash { 'printerId' => @printer_id, 'title' => @title, 'contentType' => @content_type, 'content' => load_content, 'source' => @source } end |