Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
passfaker (0.1.0)
passfaker (0.2.0)
faker (~> 2.0)

GEM
Expand Down
19 changes: 16 additions & 3 deletions lib/passfaker/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,30 @@ module Generator
-> { Faker::Creature::Animal.name },
-> { Faker::Food.ingredient },
-> { Faker::Games::Pokemon.name },
-> { Faker::Music.instrument }
-> { Faker::Music.instrument },
-> { Faker::Superhero.name },
-> { Faker::Music.genre }
].freeze

def self.generate(word_count:, separator:, include_number:)
words = word_count.times.map do
generator = CATEGORIES[SecureRandom.random_number(CATEGORIES.size)]
generator.call.downcase.gsub(/\s+/, "-")
word = generator.call.downcase.gsub(/\s+/, "")
random_char_upcase(word)
end

words << ::SecureRandom.random_number(100).to_s if include_number
words.join(separator)
words.shuffle.join(separator)
end

# ランダムな文字を大文字に変換する
def self.random_char_upcase(word)
return word if word.empty?

chars = word.chars
index = SecureRandom.random_number(chars.size)
chars[index] = chars[index].upcase
chars.join
end
end
end
2 changes: 1 addition & 1 deletion lib/passfaker/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Passfaker
VERSION = "0.1.0"
VERSION = "0.2.0"
end
2 changes: 1 addition & 1 deletion spec/passfaker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

it "includes a number when include_number is true" do
password = Passfaker.generate(include_number: true)
expect(password).to match(/\d+$/)
expect(password).to match(/\d+/)
end
end
end