Class: NOMS::Command::URInion::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/noms/command/urinion/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(urltext) ⇒ Data

Returns a new instance of Data.



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
59
60
61
# File 'lib/noms/command/urinion/data.rb', line 27

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

Instance Attribute Details

#character_setObject

Returns the value of attribute character_set.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def character_set
  @character_set
end

#dataObject

Returns the value of attribute data.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def data
  @data
end

#data_encodingObject

Returns the value of attribute data_encoding.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def data_encoding
  @data_encoding
end

#fragmentObject

Returns the value of attribute fragment.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def fragment
  @fragment
end

#hostObject

Returns the value of attribute host.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def host
  @host
end

#mime_typeObject

Returns the value of attribute mime_type.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def mime_type
  @mime_type
end

#passwordObject

Returns the value of attribute password.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def password
  @password
end

#pathObject

Returns the value of attribute path.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def path
  @path
end

#portObject

Returns the value of attribute port.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def port
  @port
end

#queryObject

Returns the value of attribute query.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def query
  @query
end

#raw_dataObject

Returns the value of attribute raw_data.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def raw_data
  @raw_data
end

#schemeObject

Returns the value of attribute scheme.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def scheme
  @scheme
end

#userObject

Returns the value of attribute user.



19
20
21
# File 'lib/noms/command/urinion/data.rb', line 19

def user
  @user
end

Class Method Details

.parse(urltext) ⇒ Object



23
24
25
# File 'lib/noms/command/urinion/data.rb', line 23

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