Sha256: 99537138e3c43704da9c591059021f86d7ea6e299d861c559c2ec2807dfe1fa5

Contents?: true

Size: 1.61 KB

Versions: 27

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require 'active_model'
require_relative '../support/descriptable'
require_relative '../support/presentable'
require_relative '../validators/description_validator'

module Dsu
  module Models
    # This class represents something someone might want to share at their
    # daily standup (DSU).
    class Entry
      include ActiveModel::Model
      include Support::Descriptable
      include Support::Presentable

      MIN_DESCRIPTION_LENGTH = 2
      MAX_DESCRIPTION_LENGTH = 256

      validates_with Validators::DescriptionValidator

      attr_reader :description, :options

      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

      class << self
        def clean_description(description)
          return if description.nil?

          description.strip.gsub(/\s+/, ' ')
        end
      end

      def description=(description)
        @description = self.class.clean_description description
      end

      def to_h
        { description: description }
      end

      # 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.
      def ==(other)
        return false unless other.is_a?(Entry)

        description == other.description
      end
      alias eql? ==

      def hash
        description.hash
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
dsu-3.0.5 lib/dsu/models/entry.rb
dsu-3.0.4 lib/dsu/models/entry.rb
dsu-3.0.3 lib/dsu/models/entry.rb
dsu-3.0.1 lib/dsu/models/entry.rb
dsu-3.0.0 lib/dsu/models/entry.rb
dsu-3.0.0.beta.3 lib/dsu/models/entry.rb
dsu-3.0.0.beta.2 lib/dsu/models/entry.rb
dsu-3.0.0.beta.1 lib/dsu/models/entry.rb
dsu-3.0.0.beta.0 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.12 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.11 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.10 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.9 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.8 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.7 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.6 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.5 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.4 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.3 lib/dsu/models/entry.rb
dsu-3.0.0.alpha.2 lib/dsu/models/entry.rb