Class: Capitalism::Journal
- Inherits:
-
Object
- Object
- Capitalism::Journal
- Defined in:
- lib/capitalism/journal.rb,
lib/capitalism/journal/version.rb
Defined Under Namespace
Classes: InvalidEvent
Constant Summary collapse
- VERSION =
'0.8.2'.freeze
Instance Attribute Summary collapse
-
#event_validator ⇒ Object
readonly
Returns the value of attribute event_validator.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #add(timestamp: Time.now, value: true) ⇒ Object
- #add_timestamp(timestamp) ⇒ Object
- #add_value(value) ⇒ Object
- #delete_at(index) ⇒ Object
-
#initialize(event_validator = ->(_event) { true }) ⇒ Journal
constructor
A new instance of Journal.
- #timestamps ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(event_validator = ->(_event) { true }) ⇒ Journal
Returns a new instance of Journal.
10 11 12 13 |
# File 'lib/capitalism/journal.rb', line 10 def initialize(event_validator = ->(_event) { true }) @event_validator = event_validator @events = [] end |
Instance Attribute Details
#event_validator ⇒ Object (readonly)
Returns the value of attribute event_validator.
8 9 10 |
# File 'lib/capitalism/journal.rb', line 8 def event_validator @event_validator end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
8 9 10 |
# File 'lib/capitalism/journal.rb', line 8 def events @events end |
Instance Method Details
#add(timestamp: Time.now, value: true) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/capitalism/journal.rb', line 15 def add(timestamp: Time.now, value: true) event = OpenStruct.new({ journal: self, timestamp: , value: value }) raise InvalidEvent unless event_validator.call(event) @events << event nil end |
#add_timestamp(timestamp) ⇒ Object
26 27 28 |
# File 'lib/capitalism/journal.rb', line 26 def () add(timestamp: ) end |
#add_value(value) ⇒ Object
22 23 24 |
# File 'lib/capitalism/journal.rb', line 22 def add_value(value) add(value: value) end |
#delete_at(index) ⇒ Object
38 39 40 41 |
# File 'lib/capitalism/journal.rb', line 38 def delete_at(index) @events.delete_at(index) nil end |
#timestamps ⇒ Object
30 31 32 |
# File 'lib/capitalism/journal.rb', line 30 def events.map(&:timestamp) end |
#values ⇒ Object
34 35 36 |
# File 'lib/capitalism/journal.rb', line 34 def values events.map(&:value) end |