Class: DynamicPDFApi::AdditionalResource
- Defined in:
- lib/ruby_client/AdditionalResource.rb
Instance Attribute Summary collapse
-
#_mime_type ⇒ Object
Returns the value of attribute _mime_type.
-
#default_page_height ⇒ Object
Returns the value of attribute default_page_height.
-
#default_page_width ⇒ Object
Returns the value of attribute default_page_width.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Resource
#_file_path, #data, #resource_name
Instance Method Summary collapse
- #file_extension=(value) ⇒ Object
- #get_resource_type(resourcePath) ⇒ Object
-
#initialize(resource, resource_name, resource_type = nil) ⇒ AdditionalResource
constructor
A new instance of AdditionalResource.
Methods inherited from Resource
#_file_extension, _get_file_data
Constructor Details
#initialize(resource, resource_name, resource_type = nil) ⇒ AdditionalResource
Returns a new instance of AdditionalResource.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_client/AdditionalResource.rb', line 6 def initialize(resource, resource_name, resource_type=nil) @default_page_height = 792.0 @default_page_width = 612.0 @type = ResourceType::LAYOUT_DATA if (resource.is_a?(Array)) == true super(resource, resource_name) @type = resource_type else super(resource, resource_name) @type = get_resource_type(resource) end end |
Instance Attribute Details
#_mime_type ⇒ Object
Returns the value of attribute _mime_type.
109 110 111 |
# File 'lib/ruby_client/AdditionalResource.rb', line 109 def _mime_type @_mime_type end |
#default_page_height ⇒ Object
Returns the value of attribute default_page_height.
110 111 112 |
# File 'lib/ruby_client/AdditionalResource.rb', line 110 def default_page_height @default_page_height end |
#default_page_width ⇒ Object
Returns the value of attribute default_page_width.
111 112 113 |
# File 'lib/ruby_client/AdditionalResource.rb', line 111 def default_page_width @default_page_width end |
#type ⇒ Object
Returns the value of attribute type.
108 109 110 |
# File 'lib/ruby_client/AdditionalResource.rb', line 108 def type @type end |
Instance Method Details
#file_extension=(value) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ruby_client/AdditionalResource.rb', line 60 def file_extension=(value) @file_extension = value case (@type) when ResourceType::IMAGE @file_header = @data[0, 16] @file_header = @file_header.bytes if (ImageResource.is_png_image(@file_header)) @_mime_type = "image/png" elsif (ImageResource.is_jpeg_image(@file_header)) @_mime_type = "image/jpeg" elsif (ImageResource.is_gif_image(@file_header)) @_mime_type = "image/gif" elsif (ImageResource.is_tiff_image(@file_header)) @_mime_type = "image/tiff" elsif (ImageResource.is_jpeg2000_image(@file_header)) @_mime_type = "image/jpeg" elsif (ImageResource.is_valid_bitmap_image(@file_header)) @_mime_type = "image/bmp" else raise "Not supported image type or invalid image." end when ResourceType::PDF @_mime_type = "application/pdf" ".pdf" when ResourceType::LAYOUT_DATA @_mime_type = "application/json" ".json" when ResourceType::DLEX @_mime_type = "application/xml" ".dlex" when ResourceType::FONT if (Data[0] == 0x4f && Data[1] == 0x54 && Data[2] == 0x54 && Data[3] == 0x4f) @_mime_type = "font/otf" ".otf" elsif (Data[0] == 0x00 && Data[1] == 0x01 && Data[2] == 0x00 && Data[3] == 0x00) @_mime_type = "font/ttf" ".ttf" else raise "Unsupported font" end when ResourceType::Html @_mime_type = "text/html" ".html" end nil end |
#get_resource_type(resourcePath) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby_client/AdditionalResource.rb', line 20 def get_resource_type(resourcePath) @type = ResourceType::PDF file_extension = File.extname(resourcePath).downcase case (file_extension) when ".pdf" @type = ResourceType::PDF when ".dlex" @type = ResourceType::DLEX when ".json" @type = ResourceType::LAYOUT_DATA when ".ttf" when ".otf" @type = ResourceType::FONT when ".tiff" @type = ResourceType::IMAGE when ".tif" @type = ResourceType::IMAGE when ".png" @type = ResourceType::IMAGE when ".gif" @type = ResourceType::IMAGE when ".jpeg" @type = ResourceType::IMAGE when ".jpg" @type = ResourceType::IMAGE when ".bmp" @type = ResourceType::IMAGE when ".html" @type = ResourceType::HTML end @type end |