Sha256: e11ac6f6c5f9c763921a356ac8b9c4f400506f1110f3a8dbd8c29437407b0a4c

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Support
    class Value
      ##
      # @!attribute [r] label
      #   @return [String]
      #
      attr_reader :label

      ##
      # @param label [String]
      # @return [void]
      #
      def initialize(label = default_label)
        @label = label
      end

      ##
      # @param other [Object] Can be any type.
      # @return [Boolean]
      #
      def ==(other)
        return unless other.instance_of?(self.class)

        label == other.label
      end

      ##
      # @param other [Object] Can be any type.
      # @return [Boolean]
      #
      def ===(other)
        self == other
      end

      ##
      # @param other [Object] Can be any type.
      # @return [Boolean]
      #
      def eql?(other)
        return unless other.instance_of?(self.class)

        hash == other.hash
      end

      ##
      # @return [Integer]
      #
      # @internal
      #   IMPORTANT: What to do with collisions?
      #
      def hash
        label.hash
      end

      ##
      # @return [String]
      #
      def inspect
        return default_label if label.nil?
        return default_label if label.empty?

        label
      end

      private

      ##
      # @return [String]
      #
      def default_label
        "value"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/support/value.rb
convenient_service-0.19.0 lib/convenient_service/support/value.rb
convenient_service-0.18.0 lib/convenient_service/support/value.rb