File tree Expand file tree Collapse file tree 4 files changed +19
-6
lines changed
Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 11PATH
22 remote: .
33 specs:
4- passfaker (0.1 .0 )
4+ passfaker (0.2 .0 )
55 faker (~> 2.0 )
66
77GEM
Original file line number Diff line number Diff 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
2841end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33module Passfaker
4- VERSION = "0.1 .0"
4+ VERSION = "0.2 .0"
55end
Original file line number Diff line number Diff line change 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
2626end
You can’t perform that action at this time.
0 commit comments