biscotti 0.1.3 → 0.1.4

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.
@@ -12,36 +12,19 @@ $LOAD_PATH.unshift("#{__dir__}/../lib")
12
12
  require 'biscotti'
13
13
  require 'biscotti/cli'
14
14
 
15
- require 'optparse'
16
-
17
- OptionParser.new do |opts|
18
- opts.banner = 'Usage: bundle exec biscotti [--version] [--help] <letters>'
15
+ BISCOTTI_HOME = File.realpath(File.join(File.dirname(__FILE__), '..'))
19
16
 
20
- opts.on('-V', '--version', 'Print version info') do
21
- $stdout.puts("biscotti version #{Biscotti::VERSION}")
22
- exit(0)
23
- end
17
+ begin
18
+ options = Biscotti::CLI::OptParser.parse!(ARGV)
24
19
 
25
- # TODO: Print dictionary
26
- # TODO: Minimum character count
27
- # TODO: Provide a custom dictionary
28
- # TODO: Output as a grouped list by word length
29
- # TODO: Verbose mode to emit more than just the list
30
- # TODO: Alternative formats mode: JSON, Yaml, Text (default)
20
+ dictionary_file = options.fetch(:dictionary, File.join(BISCOTTI_HOME, 'data', 'biscotti', 'words.lst')).freeze
31
21
 
32
- opts.on_tail('-h', '--help', 'Show this message') do
33
- warn(opts)
34
- exit(0)
35
- end
36
- end.parse!
22
+ # Raise error if dictionary file doesn't exist or cannot be read.
37
23
 
38
- # raise 'File not processable' unless Biscotti::CLI.processable?
24
+ dictionary = Biscotti.load_dictionary(dictionary_file).freeze
39
25
 
40
- BISCOTTI_HOME = File.realpath(File.join(File.dirname(__FILE__), '..'))
41
-
42
- begin
43
- dictionary = Biscotti.load_dictionary(File.join(BISCOTTI_HOME, 'data', 'biscotti', 'words.lst').freeze)
44
26
  letters = ARGV.flat_map { |word| word.downcase.split('') }.sort.join
27
+
45
28
  min_word_length = 2
46
29
 
47
30
  output = Biscotti.find_words(
@@ -34,10 +34,12 @@ module Biscotti
34
34
  w.concat(letters.permutation(letter_count).to_a.map(&:join))
35
35
  end
36
36
 
37
+ letters_count = letters.count
38
+ word_length_range = (min_word_length..letters_count).freeze
39
+
37
40
  words & dictionary
38
41
  .map(&:chomp)
39
- .select { |word| word.length >= min_word_length }
40
- .select { |word| word.length <= letters.count }
42
+ .select { |word| word_length_range.include?(word.length) }
41
43
  .map { |word| word.strip.downcase.split('') }
42
44
  .select { |word| (word - letters).empty? }
43
45
  .select { |word| word.all? { |l0| word.count { |l1| l1 == l0 } <= letters_frequency_idx[l0] } }
@@ -1,13 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'optparse'
4
+
3
5
  module Biscotti
4
6
  module CLI
5
- def self.run(app, io)
6
- # app.new(railroad: Sodor::Railroad::Marshal.load(io))
7
- end
7
+ class OptParser
8
+ def self.parse!(args)
9
+ options = {}
10
+
11
+ parser = OptionParser.new do |opts|
12
+ opts.banner = 'Usage: bundle exec biscotti [--version] [--help] [--dictionary=/path/to/words.lst] <letters>'
13
+
14
+ opts.on('-V', '--version', 'Print version info') do
15
+ $stdout.puts("biscotti version #{Biscotti::VERSION}")
16
+ exit(0)
17
+ end
18
+
19
+ opts.on('-D', '--dictionary=DICTIONARY', 'Path to the words list') do |dictionary|
20
+ options[:dictionary] = dictionary
21
+ end
22
+
23
+ # TODO: Print dictionary
24
+ # TODO: Minimum character count
25
+ # TODO: Provide a custom dictionary
26
+ # TODO: Output as a grouped list by word length
27
+ # TODO: Verbose mode to emit more than just the list
28
+ # TODO: Alternative formats mode: JSON, Yaml, Text (default)
29
+
30
+ opts.on_tail('-h', '--help', 'Show this message') do
31
+ warn(opts)
32
+ exit(0)
33
+ end
34
+ end
35
+
36
+ begin
37
+ parser.parse!(args)
38
+ rescue StandardError => e
39
+ puts e.message
40
+
41
+ exit(1)
42
+ end
43
+
44
+ options[:letters] = ARGV
8
45
 
9
- def self.processable?
10
- ARGF.filename != '-' || !(STDIN.tty? || STDIN.closed?)
46
+ options
47
+ end
11
48
  end
12
49
  end
13
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Biscotti
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biscotti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Hall
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-12 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -105,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.7.7
108
+ rubygems_version: 3.0.4
110
109
  signing_key:
111
110
  specification_version: 4
112
111
  summary: Totally not a way to cheat at letter scramble games.