Class: Dsu::Models::Entry

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Presentable

#presenter

Methods included from Support::Descriptable

included, #short_description

Constructor Details

#initialize(description:, options: {}) ⇒ Entry

Returns a new instance of Entry.

Raises:

  • (ArgumentError)


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 = options || {}
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



22
23
24
# File 'lib/dsu/models/entry.rb', line 22

def description
  @description
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/dsu/models/entry.rb', line 22

def options
  @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

#hashObject



58
59
60
# File 'lib/dsu/models/entry.rb', line 58

def hash
  description.hash
end

#to_hObject



44
45
46
# File 'lib/dsu/models/entry.rb', line 44

def to_h
  { description: description }
end