Skip to content

Commit

Permalink
Merge pull request #16 from mitchellhenke/remove-ostruct
Browse files Browse the repository at this point in the history
Remove OpenStruct usage
  • Loading branch information
formigarafa authored Oct 29, 2024
2 parents 812a4b1 + 6a5159c commit cf6da7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/zxcvbn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@

module Zxcvbn
class Error < StandardError; end
Result = Struct.new(
:password,
:guesses,
:guesses_log10,
:sequence,
:calc_time,
:crack_times_seconds,
:crack_times_display,
:score,
:feedback,
keyword_init: true
)

def self.zxcvbn(password, user_inputs = [])
start = (Time.now.to_f * 1000).to_i
Expand All @@ -25,7 +37,7 @@ def self.zxcvbn(password, user_inputs = [])
end

def self.test(password, user_inputs = [])
OpenStruct.new(Zxcvbn.zxcvbn(password, user_inputs)) # rubocop:disable Style/OpenStructUse
Result.new(Zxcvbn.zxcvbn(password, user_inputs))
end

class Tester
Expand Down
4 changes: 2 additions & 2 deletions spec/zxcvbn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@
normal_result = Zxcvbn.zxcvbn("@lfred2004", ["alfred"]).reject { |k, _v| ["calc_time"].include? k }
result1 = Zxcvbn.test("@lfred2004", ["alfred"])
result2 = Zxcvbn::Tester.new.test("@lfred2004", ["alfred"])
expect(result1).to be_a(OpenStruct) # rubocop:disable Style/OpenStructUse
expect(result1).to be_a(Zxcvbn::Result)
expect(result1.to_h.transform_keys(&:to_s).reject { |k, _v| ["calc_time"].include? k }).to eq(normal_result)
expect(result2).to be_a(OpenStruct) # rubocop:disable Style/OpenStructUse
expect(result2).to be_a(Zxcvbn::Result)
expect(result2.to_h.transform_keys(&:to_s).reject { |k, _v| ["calc_time"].include? k }).to eq(normal_result)
end
end

0 comments on commit cf6da7c

Please sign in to comment.