Class: Saro::Dat::Dat

Inherits:
Object
  • Object
show all
Defined in:
lib/saro/dat/dat.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dat_str) ⇒ Dat

Returns a new instance of Dat.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/saro/dat/dat.rb', line 10

def initialize(dat_str)
  @dat = dat_str || ''
  @format = false
  @expire = 0
  @cid = 0
  @plain = "".b
  @secure = "".b
  @signature = "".b

  if !@dat.empty?
    parts = @dat.split('.')
    if parts.length == 5
      begin
        @expire = parts[0].to_i
        @cid = parts[1].to_i(16)
        @plain = Saro::Dat::Util.decode_base64_url(parts[2])
        @secure = Saro::Dat::Util.decode_base64_url(parts[3])
        @signature = Saro::Dat::Util.decode_base64_url(parts[4])
        @format = (!@signature.empty? && @expire >= 0)
      rescue StandardError
        @format = false
      end
    end
  end
end

Instance Attribute Details

#cidObject (readonly)

Returns the value of attribute cid.



8
9
10
# File 'lib/saro/dat/dat.rb', line 8

def cid
  @cid
end

#datObject (readonly)

Returns the value of attribute dat.



8
9
10
# File 'lib/saro/dat/dat.rb', line 8

def dat
  @dat
end

#expireObject (readonly)

Returns the value of attribute expire.



8
9
10
# File 'lib/saro/dat/dat.rb', line 8

def expire
  @expire
end

#formatObject (readonly)

Returns the value of attribute format.



8
9
10
# File 'lib/saro/dat/dat.rb', line 8

def format
  @format
end

#plainObject (readonly)

Returns the value of attribute plain.



8
9
10
# File 'lib/saro/dat/dat.rb', line 8

def plain
  @plain
end

#secureObject (readonly)

Returns the value of attribute secure.



8
9
10
# File 'lib/saro/dat/dat.rb', line 8

def secure
  @secure
end

#signatureObject (readonly)

Returns the value of attribute signature.



8
9
10
# File 'lib/saro/dat/dat.rb', line 8

def signature
  @signature
end

Class Method Details

.from_value(value) ⇒ Object



36
37
38
39
# File 'lib/saro/dat/dat.rb', line 36

def self.from_value(value)
  return value if value.is_a?(Dat)
  new(value)
end

Instance Method Details

#body_stringObject



46
47
48
49
# File 'lib/saro/dat/dat.rb', line 46

def body_string
  return "" unless @dat.include?('.')
  @dat.rpartition('.').first
end

#expired?Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/saro/dat/dat.rb', line 41

def expired?
  return true unless @format
  Time.now.to_i > @expire
end