Class: DynamicPDFApi::Resource
- Inherits:
-
Object
- Object
- DynamicPDFApi::Resource
- Defined in:
- lib/ruby_client/Resource.rb
Direct Known Subclasses
AdditionalResource, DlexResource, ExcelResource, FontResource, HtmlResource, ImageResource, LayoutDataResource, PdfResource, WordResource
Instance Attribute Summary collapse
-
#_file_path ⇒ Object
Returns the value of attribute _file_path.
-
#_mime_type ⇒ Object
Returns the value of attribute _mime_type.
-
#data ⇒ Object
Returns the value of attribute data.
-
#resource_name ⇒ Object
Gets or sets the resource name.
Class Method Summary collapse
Instance Method Summary collapse
- #_file_extension ⇒ Object
-
#initialize(file = nil, resource_name = nil) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(file = nil, resource_name = nil) ⇒ Resource
Returns a new instance of Resource.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_client/Resource.rb', line 7 def initialize(file = nil, resource_name = nil) @_name = nil @_type = nil @_file_path = nil @_mime_type = '' unless file.nil? if (file.is_a?(Array)) == true @data = file.pack('c*') elsif file.is_a?(String) if File.exist?(file) @_file_path = file @data = Resource._get_file_data(file) else raise "#{file} : File does not exist." end else @data = file.read end @resource_name = if resource_name.nil? SecureRandom.uuid + _file_extension else resource_name end @_mime_type = '' end end |
Instance Attribute Details
#_file_path ⇒ Object
Returns the value of attribute _file_path.
36 37 38 |
# File 'lib/ruby_client/Resource.rb', line 36 def _file_path @_file_path end |
#_mime_type ⇒ Object
Returns the value of attribute _mime_type.
36 37 38 |
# File 'lib/ruby_client/Resource.rb', line 36 def _mime_type @_mime_type end |
#data ⇒ Object
Returns the value of attribute data.
36 37 38 |
# File 'lib/ruby_client/Resource.rb', line 36 def data @data end |
#resource_name ⇒ Object
Gets or sets the resource name.
41 42 43 |
# File 'lib/ruby_client/Resource.rb', line 41 def resource_name @resource_name end |
Class Method Details
._get_file_data(file_path) ⇒ Object
47 48 49 |
# File 'lib/ruby_client/Resource.rb', line 47 def self._get_file_data(file_path) File.binread(file_path) end |
Instance Method Details
#_file_extension ⇒ Object
43 44 45 |
# File 'lib/ruby_client/Resource.rb', line 43 def _file_extension File.extname(@_file_path) unless @_file_path.nil? end |