Class: Teton::Entry
- Inherits:
-
Object
- Object
- Teton::Entry
- Defined in:
- lib/teton/entry.rb
Overview
Describe what data should be returned when requested.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #[](data_key) ⇒ Object
-
#initialize(key, data: {}, created_at: Time.now.utc, updated_at: Time.now.utc) ⇒ Entry
constructor
A new instance of Entry.
- #to_s ⇒ Object
Constructor Details
#initialize(key, data: {}, created_at: Time.now.utc, updated_at: Time.now.utc) ⇒ Entry
Returns a new instance of Entry.
8 9 10 11 12 13 14 15 |
# File 'lib/teton/entry.rb', line 8 def initialize(key, data: {}, created_at: Time.now.utc, updated_at: Time.now.utc) @key = key.to_s @data = (data || {}).transform_keys(&:to_s) @created_at = created_at || Time.now.utc @updated_at = updated_at || Time.now.utc freeze end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/teton/entry.rb', line 6 def created_at @created_at end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/teton/entry.rb', line 6 def data @data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/teton/entry.rb', line 6 def key @key end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
6 7 8 |
# File 'lib/teton/entry.rb', line 6 def updated_at @updated_at end |
Instance Method Details
#[](data_key) ⇒ Object
17 18 19 |
# File 'lib/teton/entry.rb', line 17 def [](data_key) data[data_key.to_s] end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/teton/entry.rb', line 21 def to_s "[#{key} |> #{created_at} | #{updated_at}] #{data.map { |k, v| "#{k}: #{v}" }.join(', ')}" end |