Sha256: fc6e7525795aba9ce70459af1f01e097e8c36932852210397661376ec2db2c7e

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module CodebreakerManflu
  class UserStatistics < ValidatableEntity
    include Validator
    attr_reader :user, :difficulty, :attempts, :hints, :date

    def initialize(user:, difficulty:, attempts:, hints:)
      super()
      @user = user
      @difficulty = difficulty
      @attempts = attempts
      @hints = hints
      @date = DateTime.now
    end

    private

    def validate
      add_error(:user, I18n.t(:unexpected_class_error)) unless valid_class?(CodebreakerManflu::User, user)
      add_error(:difficulty, I18n.t(:unexpected_class_error)) unless valid_class?(CodebreakerManflu::Difficulty,
                                                                                  difficulty)
      validate_attempts
      validate_hints
    end

    def validate_attempts
      return add_error(:attempts, I18n.t(:unexpected_class_error)) unless valid_class?(Integer, attempts)

      add_error(:attempts, I18n.t(:negative_integer_error)) unless valid_non_negative_integer?(attempts)
    end

    def validate_hints
      return add_error(:hints, I18n.t(:unexpected_class_error)) unless valid_class?(Integer, hints)

      add_error(:hints, I18n.t(:negative_integer_error)) unless valid_non_negative_integer?(hints)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebreker_manfly-0.1.1 lib/codebreker_manfly/entities/user_statistics.rb