Class: Teton::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/teton/entry.rb

Overview

Describe what data should be returned when requested.

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/teton/entry.rb', line 6

def created_at
  @created_at
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/teton/entry.rb', line 6

def data
  @data
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/teton/entry.rb', line 6

def key
  @key
end

#updated_atObject (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_sObject



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