Class: ToiletTracker::Core::Message
- Inherits:
-
Data
- Object
- Data
- ToiletTracker::Core::Message
- Defined in:
- lib/toilet_tracker/core/message.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#sender ⇒ Object
readonly
Returns the value of attribute sender.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #age_in_days ⇒ Object
-
#initialize(timestamp:, sender:, content:) ⇒ Message
constructor
A new instance of Message.
- #recent?(days: 30) ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(timestamp:, sender:, content:) ⇒ Message
Returns a new instance of Message.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/toilet_tracker/core/message.rb', line 9 def initialize(timestamp:, sender:, content:) = case when Time, ActiveSupport::TimeWithZone when String Time.parse() else raise ArgumentError, "Invalid timestamp type: #{timestamp.class}" end super( timestamp: , sender: sender.to_s.strip, content: content.to_s ) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content
8 9 10 |
# File 'lib/toilet_tracker/core/message.rb', line 8 def content @content end |
#sender ⇒ Object (readonly)
Returns the value of attribute sender
8 9 10 |
# File 'lib/toilet_tracker/core/message.rb', line 8 def sender @sender end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp
8 9 10 |
# File 'lib/toilet_tracker/core/message.rb', line 8 def end |
Instance Method Details
#age_in_days ⇒ Object
32 33 34 |
# File 'lib/toilet_tracker/core/message.rb', line 32 def age_in_days (Time.current - ) / 1.day end |
#recent?(days: 30) ⇒ Boolean
36 37 38 |
# File 'lib/toilet_tracker/core/message.rb', line 36 def recent?(days: 30) age_in_days <= days end |
#valid? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/toilet_tracker/core/message.rb', line 26 def valid? .is_a?(Time) && !sender.empty? && !content.empty? end |