class CarrierWave::Neo4j::DataUri::Parser

Attributes

data[R]
encoder[R]
extension[R]
type[R]

Public Class Methods

new(data_uri) click to toggle source
# File lib/carrierwave/neo4j_data_uri/parser.rb, line 9
def initialize(data_uri)
  if data_uri.match /^data:(.*?);(.*?),(.*)$/
    @type = $1
    @encoder = $2
    @data = $3
    @extension = $1.split('/')[1]
  else
    raise ArgumentError, 'Invalid data'
  end
end

Public Instance Methods

binary_data() click to toggle source
# File lib/carrierwave/neo4j_data_uri/parser.rb, line 20
def binary_data
  @binary_data ||= Base64.decode64 data
end
to_file(options = {}) click to toggle source
# File lib/carrierwave/neo4j_data_uri/parser.rb, line 24
def to_file(options = {})
  @file ||= begin
    file = Tempfile.new ['data_uri_upload', ".#{extension}"]
    file.binmode
    file << binary_data
    file.rewind
    file.original_filename = options[:original_filename]
    file.content_type = options[:content_type]
    file
  end
end