Class: Saro::Dat::Dat
- Inherits:
-
Object
- Object
- Saro::Dat::Dat
- Defined in:
- lib/saro/dat/dat.rb
Instance Attribute Summary collapse
-
#cid ⇒ Object
readonly
Returns the value of attribute cid.
-
#dat ⇒ Object
readonly
Returns the value of attribute dat.
-
#expire ⇒ Object
readonly
Returns the value of attribute expire.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#plain ⇒ Object
readonly
Returns the value of attribute plain.
-
#secure ⇒ Object
readonly
Returns the value of attribute secure.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Class Method Summary collapse
Instance Method Summary collapse
- #body_string ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(dat_str) ⇒ Dat
constructor
A new instance of Dat.
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
#cid ⇒ Object (readonly)
Returns the value of attribute cid.
8 9 10 |
# File 'lib/saro/dat/dat.rb', line 8 def cid @cid end |
#dat ⇒ Object (readonly)
Returns the value of attribute dat.
8 9 10 |
# File 'lib/saro/dat/dat.rb', line 8 def dat @dat end |
#expire ⇒ Object (readonly)
Returns the value of attribute expire.
8 9 10 |
# File 'lib/saro/dat/dat.rb', line 8 def expire @expire end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/saro/dat/dat.rb', line 8 def format @format end |
#plain ⇒ Object (readonly)
Returns the value of attribute plain.
8 9 10 |
# File 'lib/saro/dat/dat.rb', line 8 def plain @plain end |
#secure ⇒ Object (readonly)
Returns the value of attribute secure.
8 9 10 |
# File 'lib/saro/dat/dat.rb', line 8 def secure @secure end |
#signature ⇒ Object (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_string ⇒ Object
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
41 42 43 44 |
# File 'lib/saro/dat/dat.rb', line 41 def expired? return true unless @format Time.now.to_i > @expire end |