Class: Dsu::Models::Entry
- Inherits:
-
Object
- Object
- Dsu::Models::Entry
- Includes:
- ActiveModel::Model, Support::Descriptable, Support::Presentable
- Defined in:
- lib/dsu/models/entry.rb
Overview
This class represents something someone might want to share at their daily standup (DSU).
Constant Summary collapse
- MIN_DESCRIPTION_LENGTH =
2
- MAX_DESCRIPTION_LENGTH =
256
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Override == and hash so that we can compare Entry objects based on description alone.
- #hash ⇒ Object
-
#initialize(description:, options: {}) ⇒ Entry
constructor
A new instance of Entry.
- #to_h ⇒ Object
Methods included from Support::Presentable
Methods included from Support::Descriptable
Constructor Details
#initialize(description:, options: {}) ⇒ Entry
Returns a new instance of Entry.
24 25 26 27 28 29 30 |
# File 'lib/dsu/models/entry.rb', line 24 def initialize(description:, options: {}) raise ArgumentError, 'description is the wrong object type' unless description.is_a?(String) # Make sure to call the setter method so that the description is cleaned up. self.description = description @options = || {} end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
22 23 24 |
# File 'lib/dsu/models/entry.rb', line 22 def description @description end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/dsu/models/entry.rb', line 22 def @options end |
Class Method Details
.clean_description(description) ⇒ Object
33 34 35 36 37 |
# File 'lib/dsu/models/entry.rb', line 33 def clean_description(description) return if description.nil? description.strip.gsub(/\s+/, ' ') end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Override == and hash so that we can compare Entry objects based on description alone. This is useful for comparing entries in an array, for example.
51 52 53 54 55 |
# File 'lib/dsu/models/entry.rb', line 51 def ==(other) return false unless other.is_a?(Entry) description == other.description end |
#hash ⇒ Object
58 59 60 |
# File 'lib/dsu/models/entry.rb', line 58 def hash description.hash end |
#to_h ⇒ Object
44 45 46 |
# File 'lib/dsu/models/entry.rb', line 44 def to_h { description: description } end |