Class: CFPropertyList::CFData

Inherits:
CFType
  • Object
show all
Defined in:
lib/rbCFTypes.rb

Overview

This class contains binary data values

Constant Summary collapse

DATA_BASE64 =

Base64 encoded data

0
DATA_RAW =

Raw data

1

Instance Attribute Summary

Attributes inherited from CFType

#value

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, format = DATA_BASE64) ⇒ CFData

set value to defined state, either base64 encoded or raw



170
171
172
173
174
175
176
# File 'lib/rbCFTypes.rb', line 170

def initialize(value=nil,format=DATA_BASE64)
  if(format == DATA_RAW)
    @raw_value = value
  else
    @value = value
  end
end

Instance Method Details

#decoded_valueObject

get base64 decoded value



184
185
186
# File 'lib/rbCFTypes.rb', line 184

def decoded_value
  @raw_value ||= Blob.new(Base64.decode64(@value))
end

#encoded_valueObject

get base64 encoded value



179
180
181
# File 'lib/rbCFTypes.rb', line 179

def encoded_value
  @value ||= "\n#{Base64.encode64(@raw_value).gsub("\n", '').scan(/.{1,76}/).join("\n")}\n"
end

#to_binary(bplist) ⇒ Object

convert to binary



196
197
198
# File 'lib/rbCFTypes.rb', line 196

def to_binary(bplist)
  bplist.data_to_binary(decoded_value())
end

#to_xml(parser) ⇒ Object

convert to XML



189
190
191
192
193
# File 'lib/rbCFTypes.rb', line 189

def to_xml(parser)
  n = parser.new_node('data')
  n = parser.append_node(n, parser.new_text(encoded_value()))
  n
end