Class: Shhh::Data::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/shhh/data/decoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_encoded, compress) ⇒ Decoder

Returns a new instance of Decoder


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shhh/data/decoder.rb', line 9

def initialize(data_encoded, compress)
  self.data_encoded = data_encoded
  self.data         = begin
    Base64.urlsafe_decode64(data_encoded)
  rescue
    data_encoded
  end

  if compress.nil? || compress # auto-guess
    self.data = begin
      Zlib::Inflate.inflate(data)
    rescue Zlib::Error => e
      data
    end
  end
  self.data = Marshal.load(data)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data


7
8
9
# File 'lib/shhh/data/decoder.rb', line 7

def data
  @data
end

#data_encodedObject

Returns the value of attribute data_encoded


7
8
9
# File 'lib/shhh/data/decoder.rb', line 7

def data_encoded
  @data_encoded
end