Skip to content

Commit 3160e59

Browse files
authored
Merge pull request #1 from jacoyutorius/v2
いくつか気になった箇所を改修
2 parents c143041 + 9a504a7 commit 3160e59

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
passfaker (0.1.0)
4+
passfaker (0.2.0)
55
faker (~> 2.0)
66

77
GEM

lib/passfaker/generator.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,30 @@ module Generator
1212
-> { Faker::Creature::Animal.name },
1313
-> { Faker::Food.ingredient },
1414
-> { Faker::Games::Pokemon.name },
15-
-> { Faker::Music.instrument }
15+
-> { Faker::Music.instrument },
16+
-> { Faker::Superhero.name },
17+
-> { Faker::Music.genre }
1618
].freeze
1719

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

2427
words << ::SecureRandom.random_number(100).to_s if include_number
25-
words.join(separator)
28+
words.shuffle.join(separator)
29+
end
30+
31+
# ランダムな文字を大文字に変換する
32+
def self.random_char_upcase(word)
33+
return word if word.empty?
34+
35+
chars = word.chars
36+
index = SecureRandom.random_number(chars.size)
37+
chars[index] = chars[index].upcase
38+
chars.join
2639
end
2740
end
2841
end

lib/passfaker/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Passfaker
4-
VERSION = "0.1.0"
4+
VERSION = "0.2.0"
55
end

spec/passfaker_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
it "includes a number when include_number is true" do
2222
password = Passfaker.generate(include_number: true)
23-
expect(password).to match(/\d+$/)
23+
expect(password).to match(/\d+/)
2424
end
2525
end
2626
end

0 commit comments

Comments
 (0)