Class: Twitterscraper::Cache::Entry

Inherits:
Hash
  • Object
show all
Defined in:
lib/twitterscraper/cache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, time) ⇒ Entry

Returns a new instance of Entry.



57
58
59
60
61
# File 'lib/twitterscraper/cache.rb', line 57

def initialize(key, value, time)
  @key = key
  @value = value
  @time = time
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



55
56
57
# File 'lib/twitterscraper/cache.rb', line 55

def key
  @key
end

#timeObject (readonly)

Returns the value of attribute time.



55
56
57
# File 'lib/twitterscraper/cache.rb', line 55

def time
  @time
end

#valueObject (readonly)

Returns the value of attribute value.



55
56
57
# File 'lib/twitterscraper/cache.rb', line 55

def value
  @value
end

Class Method Details

.from_json(text) ⇒ Object



74
75
76
77
# File 'lib/twitterscraper/cache.rb', line 74

def from_json(text)
  json = JSON.parse(text)
  new(json['key'], Base64.decode64(json['value']), Time.parse(json['time']))
end

Instance Method Details

#attrsObject



63
64
65
# File 'lib/twitterscraper/cache.rb', line 63

def attrs
  {key: @key, value: @value, time: @time}
end

#to_jsonObject



67
68
69
70
71
# File 'lib/twitterscraper/cache.rb', line 67

def to_json
  hash = attrs
  hash[:value] = Base64.encode64(hash[:value])
  hash.to_json
end