Sha256: f35cb534afd57c0ad873c309c39345905961d1698e3f94d0e7e515b6ae463fcf

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

#!ruby

require 'base64'

class NOMS

end

class NOMS::Command

end

class NOMS::Command::URInion

end

class NOMS::Command::URInion::Data

    attr_accessor :scheme, :host, :port, :fragment, :query, :data, :path,
        :data_encoding, :mime_type, :user, :password, :raw_data,
        :character_set

    def self.parse(urltext)
        self.new(urltext)
    end

    def initialize(urltext)
        @host = nil
        @port = nil
        @fragment = nil
        @user = nil
        @path = nil
        @password = nil
        @character_set = nil

        @scheme, rest = urltext.split(':', 2)
        raise NOMS::Command::Error.new "URL is not data: (scheme = #{@scheme})" unless @scheme == 'data'
        meta, @raw_data = rest.split(',', 2)
        fields = meta.split(';')
        if fields[-1] == 'base64'
            @data_encoding = fields.pop
        end

        unless fields[0].nil? or fields[0].empty?
            @mime_type = fields.shift
        end

        fields.each do |field|
            if m = /charset=(.*)/.match(field)
                @character_set = m[1]
            end
        end

        case @data_encoding
        when 'base64'
            @data = Base64.urlsafe_decode64
        else
            @data = @raw_data
        end

    end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
noms-command-2.1.1 lib/noms/command/urinion/data.rb
noms-command-0.5.0 lib/noms/command/urinion/data.rb