funny_yubikey_generator 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee03f537080c0eee30e79ca418b86395103442b5b7212cb862de5065fa5af037
4
- data.tar.gz: b7351abcdaef208798a496a93d9b6529010ea965f1a4f7a3ba507e72ee9421e2
3
+ metadata.gz: 441a10e193ad1457a49322d1b2d30e95fe0cf58a7300bd6821d4ba91714eb72e
4
+ data.tar.gz: 4b074be5dc27c6a43aacee06754ac065c678b01f93b53cf22e4288424c377b3c
5
5
  SHA512:
6
- metadata.gz: cea34ab297af170a44379b8123d55def53f2bb4db9de3bd12567fecf1b6ed51c47f99eda0792d7eb6c01738ee48aa1a7d1c38b9fcb31f8e9f9d82e21099838e8
7
- data.tar.gz: f781e1fef15707693c9fb1874e125c9d322916fce9f5658be85d0e91fe62aacc774a56011306da3ff91f212be10be7ca570a1dc024de6b7ec5c80d7979326e6e
6
+ metadata.gz: 87a1faa5547f637d746d7ecb937fd9d54d1cf53a662794a46e067855d10f538f7c09b56a96dfbaf01d497f9024dc98a0e08556ec68414a80ac999062e3abd5ce
7
+ data.tar.gz: dd997e1ce8459a805dfc448d27ef45781b0dc55fa70fc34209afdf038b42d2194435ff973099f36ebc0a2f653d011d3b8cd535f40af3e7018a1b3156692ff10a
data/Gemfile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in yubikey_generator.gemspec
5
+ # Specify your gem's dependencies in funny_yubikey_generator.gemspec
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funny_yubikey_generator (0.3.0)
4
+ funny_yubikey_generator (0.5.0)
5
5
  colorize (~> 0.8.1)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FunnyYubikeyGenerator
2
2
 
3
- [![0.3.0](https://badge.fury.io/rb/funny_yubikey_generator.svg)](https://badge.fury.io/rb/funny_yubikey_generator)
3
+ [![Gem Version](https://badge.fury.io/rb/funny_yubikey_generator.svg)](https://badge.fury.io/rb/funny_yubikey_generator)
4
4
 
5
5
  Generate funny looking [yubikey OTP](https://developers.yubico.com/OTP/OTPs_Explained.html) containing words based on a dictionary.
6
6
 
@@ -37,10 +37,10 @@ dictionary = <<~DICO
37
37
  interbelligerent
38
38
  reinterference
39
39
  DICO
40
- generator = FunnyYubikeyGenerator.from_dictionary(dictionary.split("\n"))
40
+ generator = FunnyYubikeyGenerator.from_dictionary(dictionary)
41
41
  puts generator.generate(colorize: true)
42
42
 
43
- generator = FunnyYubikeyGenerator.from_dictionary(File.open("/usr/share/dict/words"))
43
+ generator = FunnyYubikeyGenerator.from_dictionary(File.read("/usr/share/dict/words"))
44
44
  puts generator.generate(colorize: false)
45
45
  ```
46
46
 
@@ -48,7 +48,7 @@ puts generator.generate(colorize: false)
48
48
 
49
49
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
50
 
51
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the `spec.version` in [funny_yubikey_generator.gemspec](funny_yubikey_generator.gemspec), and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
52
 
53
53
  ## Contributing
54
54
 
data/Rakefile CHANGED
@@ -10,10 +10,6 @@ Rake::TestTask.new(:test) do |t|
10
10
  t.test_files = FileList["test/**/*_test.rb"]
11
11
  end
12
12
 
13
- task :generate_index_words do
14
- puts FunnyYubikeyGenerator.filter_and_index_words(File.open("/usr/share/dict/words")).to_yaml
15
- end
16
-
17
13
  require "standard/rake"
18
14
 
19
15
  task default: %i[test standard]
@@ -27,7 +27,7 @@ end.parse!
27
27
 
28
28
  generator = if dictionary
29
29
  raise "Could not find file #{dictionary}" unless File.exist?(dictionary)
30
- FunnyYubikeyGenerator.new(dictionary: File.open(dictionary))
30
+ FunnyYubikeyGenerator.from_dictionary(File.read(dictionary))
31
31
  else
32
32
  FunnyYubikeyGenerator.instance
33
33
  end
@@ -1,15 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/funny_yubikey_generator"
4
-
5
3
  Gem::Specification.new do |spec|
6
4
  spec.name = "funny_yubikey_generator"
7
- spec.version = FunnyYubikeyGenerator::VERSION
5
+ spec.version = "0.5.0"
8
6
  spec.authors = ["Xavier Delamotte"]
9
7
  spec.email = ["git@xade.eu"]
10
8
 
11
- spec.summary = "Generates fun yubikeys"
12
- spec.description = "Generates fun yubikeys"
9
+ spec.summary = "Generate funny looking yubikey OTP containing words based on a dictionary."
10
+ spec.description = "Generate funny looking yubikey OTP containing words based on a dictionary."
13
11
  spec.homepage = "https://github.com/x4d3/funny_yubikey_generator"
14
12
  spec.license = "MIT"
15
13
  spec.required_ruby_version = ">= 2.6.0"
@@ -2,28 +2,24 @@
2
2
 
3
3
  require "singleton"
4
4
  require "colorize"
5
- require "set"
6
- require "yaml"
7
5
 
8
6
  class FunnyYubikeyGenerator
9
7
  include Singleton
10
- VERSION = "0.3.0"
11
8
  COLORS = %i[red green yellow blue magenta cyan]
12
- LETTERS = "cbdefghijklnrtuv".chars.to_set
13
-
9
+ LETTERS = "cbdefghijklnrtuv"
10
+ WORD_REGEX = /^[#{Regexp.quote(LETTERS)}]+{4,}$/
14
11
  private_constant :COLORS
15
12
  private_constant :LETTERS
13
+ private_constant :WORD_REGEX
16
14
 
17
15
  class << self
18
16
  def from_dictionary(dictionary)
19
- indexed_words = filter_and_index_words(dictionary)
20
- new(indexed_words: indexed_words)
17
+ words = filter_words(dictionary)
18
+ new(words: words)
21
19
  end
22
20
 
23
- def filter_and_index_words(dictionary)
24
- dictionary.map(&:strip).select { |line|
25
- line.size > 3 && line.chars.all? { |c| LETTERS.include?(c) }
26
- }.group_by(&:length)
21
+ def filter_words(dictionary)
22
+ dictionary.scan(WORD_REGEX)
27
23
  end
28
24
 
29
25
  def generate(colorize: false)
@@ -31,8 +27,8 @@ class FunnyYubikeyGenerator
31
27
  end
32
28
  end
33
29
 
34
- def initialize(indexed_words: load_default_indexed_words)
35
- @indexed_words = indexed_words
30
+ def initialize(words: load_default_words)
31
+ @indexed_words = words.group_by(&:length)
36
32
  end
37
33
 
38
34
  def generate(colorize: false)
@@ -47,8 +43,9 @@ class FunnyYubikeyGenerator
47
43
 
48
44
  private
49
45
 
50
- def load_default_indexed_words
51
- YAML.load_file(File.join(__dir__, "indexed_words.yaml"))
46
+ def load_default_words
47
+ default_file_path = File.join(__dir__, "words.txt")
48
+ File.readlines(default_file_path, chomp: true)
52
49
  end
53
50
 
54
51
  def random_partition(target, word_lengths)