Skip to content

Commit

Permalink
feat(desirability): add better validation
Browse files Browse the repository at this point in the history
  • Loading branch information
benzend committed Oct 22, 2024
1 parent 28785a6 commit dac229e
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions lib/glare/ux_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def valid?
return false unless choices.values.all? do |v|
return Glare::Util.str_is_integer?(v) if v.is_a?(String)

true
true if v.is_a?(Float) || v.is_a?(Integer)
end

true
Expand Down Expand Up @@ -237,17 +237,36 @@ def initialize(questions:)
attr_reader :questions

def valid?
return false unless questions.is_a?(Array) && questions.size

if questions.is_a?(Array) && questions.size
is_invalid = false
questions.all? do |question|
return false unless questions.all? do |question|
if question.is_a?(Hash)
missing_attributes = CHOICE_KEYS - question.keys.map(&:to_s)
is_invalid = true unless missing_attributes.empty?
return false unless missing_attributes.empty?

question.values.all? do |v|
return Glare::Util.str_is_integer?(v) if v.is_a?(String)

(v.is_a?(Integer) || v.is_a?(Float))
end

true
elsif question.is_a?(Array)
return false unless question.size == 10

return false unless question.all? do |v|
return Glare::Util.str_is_integer?(v) if v.is_a?(String)

(v.is_a?(Integer) || v.is_a?(Float))
end

true
else
false
end
return true unless is_invalid
end

false
true
end

def parse(question_index:)
Expand Down

0 comments on commit dac229e

Please sign in to comment.