spoonerize 0.1.3 → 0.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +35 -32
- data/lib/spoonerize/bumper.rb +2 -0
- data/lib/spoonerize/cli.rb +21 -24
- data/lib/spoonerize/config.rb +50 -0
- data/lib/spoonerize/log.rb +4 -2
- data/lib/spoonerize/spoonerism.rb +36 -134
- data/lib/spoonerize/version.rb +2 -2
- data/lib/spoonerize.rb +54 -7
- metadata +2 -2
- data/lib/config/lazy_words.yml +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 932ce6e7e6441c787ded513aebed0b3e0b83fa6afa83790abe8da66c9314e96b
|
|
4
|
+
data.tar.gz: 6a5dedc04324853f1bfbc63e6317b17737eab6fb10b89ae11136b598438a4f08
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b579d2925471dca724865574a82a827a5f0d31229991d1746db4890a0d4c250141daa536bbc932c829fd9d7e8f5af63e89b85846a788d23eca766219c2a60681
|
|
7
|
+
data.tar.gz: 1531172c418c2cf00e155ca5e56c888218888af9c8b6694ff7a9b3195dbda173c122058e7ac46c4705c311d7951a8c6f773aa09d4571a447da7f4781ca425168
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -104,19 +104,20 @@ Here is a list of all available options:
|
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
### Config File
|
|
107
|
-
You can create a config file called `~/.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
You can create a Ruby config file called `~/.spoonerizerc`. The CLI loads this
|
|
108
|
+
file automatically before it parses command-line options, so options set in the
|
|
109
|
+
file can still be overridden at runtime by executable flags.
|
|
110
|
+
|
|
111
|
+
```ruby
|
|
112
|
+
Spoonerize.configure do |config|
|
|
113
|
+
config.excluded_words = []
|
|
114
|
+
config.lazy = false
|
|
115
|
+
config.reverse = false
|
|
116
|
+
config.logfile_name = File.expand_path("~/.cache/spoonerize/spoonerize.csv")
|
|
117
|
+
end
|
|
116
118
|
```
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
executable's flags.
|
|
120
|
+
Because the file is Ruby, you can set only the values you want to change.
|
|
120
121
|
|
|
121
122
|
## API
|
|
122
123
|
The API is [fully
|
|
@@ -126,39 +127,41 @@ are some quick examples of how you could use this in your ruby code.
|
|
|
126
127
|
```ruby
|
|
127
128
|
require 'spoonerize'
|
|
128
129
|
|
|
129
|
-
spoonerism = Spoonerize::Spoonerism.new(%w[not too shabby])
|
|
130
|
-
|
|
130
|
+
spoonerism = Spoonerize::Spoonerism.new(%w[not too shabby])
|
|
131
|
+
|
|
132
|
+
spoonerism.to_s
|
|
133
|
+
# => tot shoo nabby
|
|
134
|
+
|
|
135
|
+
Spoonerize.configure do |config|
|
|
136
|
+
config.reverse = true
|
|
131
137
|
end
|
|
132
138
|
|
|
133
|
-
spoonerism.
|
|
139
|
+
spoonerism.to_s
|
|
134
140
|
# => shot noo tabby
|
|
135
141
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
spoonerism.logfile_name = '~/.cache/spoonerize/spoonerize.csv'
|
|
142
|
+
Spoonerize.configure do |config|
|
|
143
|
+
config.logfile_name = File.expand_path("~/.cache/spoonerize/spoonerize.csv")
|
|
144
|
+
end
|
|
141
145
|
spoonerism.save
|
|
142
146
|
```
|
|
143
147
|
|
|
144
|
-
You can also
|
|
145
|
-
initialization, or via the setter. The config file will be automatically loaded
|
|
146
|
-
if passed at initialization, before the instance is yielded so you can still
|
|
147
|
-
change the values via the block. If set via the setter, you must call
|
|
148
|
-
`#load_config_file`.
|
|
148
|
+
You can also configure Spoonerize in Ruby before creating a spoonerism:
|
|
149
149
|
|
|
150
150
|
```ruby
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
sp.reverse = true
|
|
151
|
+
Spoonerize.configure do |config|
|
|
152
|
+
config.reverse = true
|
|
154
153
|
end
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
s
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
s = Spoonerize::Spoonerism.new(%w[not too shabby])
|
|
156
|
+
s.spoonerize
|
|
157
|
+
# => shot noo tabby
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Or load a config file manually:
|
|
160
161
|
|
|
161
|
-
|
|
162
|
+
```ruby
|
|
163
|
+
Spoonerize.load_config_file("~/.spoonerizerc")
|
|
164
|
+
s = Spoonerize::Spoonerism.new(%w[not too shabby])
|
|
162
165
|
```
|
|
163
166
|
|
|
164
167
|
## Self Promotion
|
data/lib/spoonerize/bumper.rb
CHANGED
data/lib/spoonerize/cli.rb
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "optparse"
|
|
2
|
-
require "yaml"
|
|
3
4
|
|
|
4
5
|
module Spoonerize
|
|
5
6
|
##
|
|
6
7
|
# The class for handling the command-line interface.
|
|
7
8
|
class Cli
|
|
8
9
|
##
|
|
9
|
-
# The
|
|
10
|
+
# The config file the user can create to change default runtime options.
|
|
10
11
|
#
|
|
11
12
|
# @return [String]
|
|
12
|
-
|
|
13
|
-
File.expand_path(File.join(ENV["HOME"], ".spoonerize.yml")).freeze
|
|
13
|
+
CONFIG_FILE = File.expand_path(File.join(ENV["HOME"], ".spoonerizerc"))
|
|
14
14
|
|
|
15
15
|
##
|
|
16
16
|
# Creates an instance of +Spoonerism+ and runs what the user requested.
|
|
@@ -19,7 +19,7 @@ module Spoonerize
|
|
|
19
19
|
def self.execute(options = [])
|
|
20
20
|
exe = new(options)
|
|
21
21
|
|
|
22
|
-
if exe.
|
|
22
|
+
if exe.print_log?
|
|
23
23
|
exe.print_log
|
|
24
24
|
return
|
|
25
25
|
end
|
|
@@ -52,23 +52,20 @@ module Spoonerize
|
|
|
52
52
|
#
|
|
53
53
|
# @return [self]
|
|
54
54
|
def initialize(options)
|
|
55
|
+
Spoonerize.load_config_file(CONFIG_FILE) if File.file?(CONFIG_FILE)
|
|
55
56
|
@map = false
|
|
56
57
|
@save = false
|
|
57
|
-
@
|
|
58
|
+
@print_log = false
|
|
58
59
|
@options = options
|
|
59
60
|
@preferences = get_preferences
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
##
|
|
63
|
-
# Sets up an instance of +Spoonerize::Spoonerism+
|
|
64
|
-
# preferences.
|
|
64
|
+
# Sets up an instance of +Spoonerize::Spoonerism+
|
|
65
65
|
#
|
|
66
66
|
# @return [Spoonerize::Spoonerism]
|
|
67
67
|
def spoonerism
|
|
68
|
-
|
|
69
|
-
@spoonerism ||= Spoonerism.new(options, pf) do |s|
|
|
70
|
-
preferences.each { |k, v| s.send(:"#{k}=", v) }
|
|
71
|
-
end
|
|
68
|
+
@spoonerism ||= Spoonerism.new(options)
|
|
72
69
|
end
|
|
73
70
|
|
|
74
71
|
##
|
|
@@ -91,8 +88,8 @@ module Spoonerize
|
|
|
91
88
|
# Should we print to the command line?
|
|
92
89
|
#
|
|
93
90
|
# @return [Boolean]
|
|
94
|
-
def
|
|
95
|
-
@
|
|
91
|
+
def print_log?
|
|
92
|
+
@print_log
|
|
96
93
|
end
|
|
97
94
|
|
|
98
95
|
##
|
|
@@ -100,8 +97,7 @@ module Spoonerize
|
|
|
100
97
|
#
|
|
101
98
|
# @return [Integer]
|
|
102
99
|
def longest_word_length
|
|
103
|
-
@longest_word_length ||=
|
|
104
|
-
spoonerism.spoonerize.group_by(&:size).max.first.size
|
|
100
|
+
@longest_word_length ||= spoonerism.spoonerize.max_by(&:size).size
|
|
105
101
|
end
|
|
106
102
|
|
|
107
103
|
##
|
|
@@ -109,8 +105,9 @@ module Spoonerize
|
|
|
109
105
|
#
|
|
110
106
|
# @return [nil]
|
|
111
107
|
def print_log
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
Spoonerize::Log.new(Spoonerize.config.logfile_name).each do |row|
|
|
109
|
+
puts row.join(" | ")
|
|
110
|
+
end
|
|
114
111
|
end
|
|
115
112
|
|
|
116
113
|
##
|
|
@@ -119,7 +116,7 @@ module Spoonerize
|
|
|
119
116
|
# @return [nil]
|
|
120
117
|
def print_mappings
|
|
121
118
|
spoonerism.to_h.each do |k, v|
|
|
122
|
-
printf("%-#{longest_word_length}s => %s\n", k, v)
|
|
119
|
+
printf("%-#{longest_word_length + 1}s => %s\n", k, v)
|
|
123
120
|
end
|
|
124
121
|
end
|
|
125
122
|
|
|
@@ -132,22 +129,22 @@ module Spoonerize
|
|
|
132
129
|
OptionParser.new do |o|
|
|
133
130
|
o.version = ::Spoonerize::Version.to_s
|
|
134
131
|
o.on("-r", "--[no-]reverse", "Reverse flipping") do |v|
|
|
135
|
-
|
|
132
|
+
Spoonerize.config.reverse = v
|
|
136
133
|
end
|
|
137
134
|
o.on("-l", "--[no-]lazy", "Skip small words") do |v|
|
|
138
|
-
|
|
135
|
+
Spoonerize.config.lazy = v
|
|
139
136
|
end
|
|
140
137
|
o.on("-m", "--[no-]map", "Print words mapping") do |v|
|
|
141
138
|
@map = v
|
|
142
139
|
end
|
|
143
|
-
o.on("-p", "--[no-]print", "Print all entries in the log") do |v|
|
|
144
|
-
@
|
|
140
|
+
o.on("-p", "--[no-]print-log", "Print all entries in the log") do |v|
|
|
141
|
+
@print_log = v
|
|
145
142
|
end
|
|
146
143
|
o.on("-s", "--[no-]save", "Save results in log") do |v|
|
|
147
144
|
@save = v
|
|
148
145
|
end
|
|
149
146
|
o.on("--exclude=WORD", Array, "Words to skip") do |v|
|
|
150
|
-
|
|
147
|
+
Spoonerize.config.excluded_words = v
|
|
151
148
|
end
|
|
152
149
|
end.parse!(options)
|
|
153
150
|
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spoonerize
|
|
4
|
+
class Config
|
|
5
|
+
##
|
|
6
|
+
# Lazy mode. If true, words in +lazy_words+ will not be altered.
|
|
7
|
+
#
|
|
8
|
+
# @return [Boolean]
|
|
9
|
+
attr_accessor :lazy
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Words to skip when +lazy+ is true.
|
|
13
|
+
#
|
|
14
|
+
# @return [Array]
|
|
15
|
+
attr_accessor :lazy_words
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
# Words that should not be altered.
|
|
19
|
+
#
|
|
20
|
+
# @return [Array]
|
|
21
|
+
attr_accessor :excluded_words
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# When true, reverse the order of the flipping. Only makes a difference
|
|
25
|
+
# when there are more than two flip-able words.
|
|
26
|
+
#
|
|
27
|
+
# @return [Boolean]
|
|
28
|
+
attr_accessor :reverse
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# Name of the log file. Should be a fully-qualified file path.
|
|
32
|
+
#
|
|
33
|
+
# @return [String]
|
|
34
|
+
attr_accessor :logfile_name
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# Create instance of Config.
|
|
38
|
+
#
|
|
39
|
+
# @return [Spoonerize::Config]
|
|
40
|
+
def initialize
|
|
41
|
+
@lazy = false
|
|
42
|
+
@lazy_words = %w[i a an and in of the my your his her him hers to is]
|
|
43
|
+
@excluded_words = []
|
|
44
|
+
@reverse = false
|
|
45
|
+
@logfile_name = File.expand_path(
|
|
46
|
+
File.join(ENV["HOME"], ".cache", "spoonerize", "spoonerize.csv")
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/spoonerize/log.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "csv"
|
|
2
4
|
require "fileutils"
|
|
3
5
|
|
|
4
6
|
module Spoonerize
|
|
5
7
|
##
|
|
6
|
-
# Class that handles reading/writing logs.
|
|
8
|
+
# Class that handles reading/writing logs. Log file is stored as a simple CSV.
|
|
7
9
|
class Log
|
|
8
10
|
##
|
|
9
11
|
# The file name to use.
|
|
@@ -51,7 +53,7 @@ module Spoonerize
|
|
|
51
53
|
##
|
|
52
54
|
# Iterate through each line of the file.
|
|
53
55
|
#
|
|
54
|
-
# @return [
|
|
56
|
+
# @return [Enumerable]
|
|
55
57
|
def each
|
|
56
58
|
contents.each { |row| yield row }
|
|
57
59
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Spoonerize
|
|
2
4
|
##
|
|
3
5
|
# The main word-flipper.
|
|
@@ -9,178 +11,76 @@ module Spoonerize
|
|
|
9
11
|
attr_reader :words
|
|
10
12
|
|
|
11
13
|
##
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# @param [Boolean] true if should be lazy.
|
|
15
|
-
#
|
|
16
|
-
# @return [Boolean]
|
|
17
|
-
attr_writer :lazy
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
# This boolean determines if flipping should be reversed.
|
|
21
|
-
#
|
|
22
|
-
# @param [Boolean] true if should be reversed.
|
|
23
|
-
#
|
|
24
|
-
# @return [Boolean]
|
|
25
|
-
attr_writer :reverse
|
|
26
|
-
|
|
27
|
-
##
|
|
28
|
-
# The full path to the log file.
|
|
29
|
-
#
|
|
30
|
-
# @param [String] file
|
|
31
|
-
#
|
|
32
|
-
# @return [String]
|
|
33
|
-
attr_accessor :logfile_name
|
|
34
|
-
|
|
35
|
-
##
|
|
36
|
-
# The words that are to be excluded.
|
|
14
|
+
# Initialize instance.
|
|
37
15
|
#
|
|
38
16
|
# @param [Array] words
|
|
39
17
|
#
|
|
40
|
-
# @return [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
##
|
|
44
|
-
# The configuration file. Default is +nil+. If set to a string, and the file
|
|
45
|
-
# exists, it is used to set options.
|
|
46
|
-
#
|
|
47
|
-
# @return [String] file path
|
|
48
|
-
attr_reader :config_file
|
|
49
|
-
|
|
50
|
-
##
|
|
51
|
-
# The options from +config_file+ as a hash.
|
|
52
|
-
#
|
|
53
|
-
# @return [Hash] Options from +config_file+
|
|
54
|
-
attr_reader :config
|
|
55
|
-
|
|
56
|
-
##
|
|
57
|
-
# Initialize instance. You can also use the +config_file+ either by passing
|
|
58
|
-
# it at initialization, or via the setter. The config file will be
|
|
59
|
-
# automatically loaded if passed at initialization, before the instance is
|
|
60
|
-
# yielded so you can still change the values via the block. If set via the
|
|
61
|
-
# setter, you must call `#load_config_file`.
|
|
62
|
-
#
|
|
63
|
-
# @param [Array] words
|
|
64
|
-
#
|
|
65
|
-
# @param [String] config_file
|
|
66
|
-
#
|
|
67
|
-
# @example
|
|
68
|
-
# # Config file would be automatically loaded before block is executed.
|
|
69
|
-
# s = Spoonerise::Spoonerism.new(%w[not too shabby], '~/.spoonerize.yml') do |sp|
|
|
70
|
-
# sp.reverse = true # Would override setting from config file
|
|
71
|
-
# end
|
|
72
|
-
# # Config file would need to be manually loaded.
|
|
73
|
-
# s = Spoonerise::Spoonerism.new(%w[not too shabby]) do |sp|
|
|
74
|
-
# sp.config_file = '~/.spoonerize.yml'
|
|
75
|
-
# sp.reverse = true
|
|
76
|
-
# end
|
|
77
|
-
# s.load_config_file # Would override setting from initialization
|
|
78
|
-
def initialize(words, config_file = nil)
|
|
79
|
-
@config = {}
|
|
80
|
-
@excluded_words = []
|
|
18
|
+
# @return [Spoonerize::Spoonerism]
|
|
19
|
+
def initialize(words)
|
|
81
20
|
@words = words.map(&:downcase)
|
|
82
|
-
@lazy = false
|
|
83
|
-
@reverse = false
|
|
84
|
-
@config_file = config_file && File.expand_path(config_file)
|
|
85
|
-
@config_file_loaded = false
|
|
86
|
-
@logfile_name = File.expand_path(
|
|
87
|
-
File.join(ENV["HOME"], ".cache", "spoonerize", "spoonerize.csv")
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
load_config_file if config_file
|
|
91
|
-
|
|
92
|
-
yield self if block_given?
|
|
93
21
|
end
|
|
94
22
|
|
|
95
23
|
##
|
|
96
24
|
# Iterates through words array, and maps its elements to the output of
|
|
97
|
-
# flip_words.
|
|
25
|
+
# flip_words.
|
|
26
|
+
#
|
|
27
|
+
# @return [Array]
|
|
98
28
|
def spoonerize
|
|
99
|
-
raise
|
|
29
|
+
raise "Not enough words to flip" unless enough_flippable_words?
|
|
100
30
|
|
|
101
31
|
words.map.with_index { |word, idx| flip_words(word, idx) }
|
|
102
32
|
end
|
|
103
33
|
|
|
104
34
|
##
|
|
105
|
-
#
|
|
35
|
+
# Spoonerized results as a joined string.
|
|
36
|
+
#
|
|
37
|
+
# @return [String]
|
|
106
38
|
def to_s
|
|
107
39
|
spoonerize.join(" ")
|
|
108
40
|
end
|
|
109
41
|
|
|
110
42
|
##
|
|
111
|
-
#
|
|
43
|
+
# Spoonerized results as a joined hash.
|
|
44
|
+
#
|
|
45
|
+
# @return [Hash]
|
|
112
46
|
def to_h
|
|
113
47
|
words.zip(spoonerize).to_h
|
|
114
48
|
end
|
|
115
49
|
|
|
116
50
|
##
|
|
117
51
|
# Same as to_h, but as json.
|
|
52
|
+
#
|
|
53
|
+
# @return [String]
|
|
118
54
|
def to_json
|
|
119
55
|
to_h.to_json
|
|
120
56
|
end
|
|
121
57
|
|
|
122
58
|
##
|
|
123
|
-
#
|
|
59
|
+
# True if there are more than one non-excluded word to flip
|
|
124
60
|
#
|
|
125
61
|
# @return [Boolean]
|
|
126
|
-
def config_file_loaded?
|
|
127
|
-
@config_file_loaded
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
##
|
|
131
|
-
# Returns true if there are more than one non-excluded word to flip
|
|
132
62
|
def enough_flippable_words?
|
|
133
63
|
(words - all_excluded_words).size > 1
|
|
134
64
|
end
|
|
135
65
|
|
|
136
|
-
##
|
|
137
|
-
# Should the lazy words be excluded?
|
|
138
|
-
def lazy?
|
|
139
|
-
@lazy
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
##
|
|
143
|
-
# Should the words flip the other direction?
|
|
144
|
-
def reverse?
|
|
145
|
-
@reverse
|
|
146
|
-
end
|
|
147
|
-
|
|
148
66
|
##
|
|
149
67
|
# Saves the flipped words to the log file, along with the options
|
|
68
|
+
#
|
|
69
|
+
# @return [Array]
|
|
150
70
|
def save
|
|
151
71
|
log.write([words.join(" "), to_s, options.join(", ")])
|
|
152
72
|
end
|
|
153
73
|
|
|
154
74
|
##
|
|
155
|
-
#
|
|
156
|
-
# * Any
|
|
157
|
-
# * Any
|
|
158
|
-
# * If lazy-mode, the LAZY_WORDS from yaml file are added
|
|
159
|
-
def all_excluded_words
|
|
160
|
-
(excluded_words + (lazy? ? LAZY_WORDS : [])).map(&:downcase)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
##
|
|
164
|
-
# Setter for +config_file+. Must be expanded in case the user uses `~` for
|
|
165
|
-
# home.
|
|
166
|
-
#
|
|
167
|
-
# @param [String] file
|
|
75
|
+
# Array of words to exclude by combining two arrays:
|
|
76
|
+
# * Any user-passed words, stored in +Spoonerize.config.excluded_words+
|
|
77
|
+
# * Any lazy words, if lazy mode is true
|
|
168
78
|
#
|
|
169
|
-
# @return [
|
|
170
|
-
def
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
##
|
|
175
|
-
# Loads the config file
|
|
176
|
-
#
|
|
177
|
-
# @return [Hash] The config options
|
|
178
|
-
def load_config_file
|
|
179
|
-
raise "No config file set" if config_file.nil?
|
|
180
|
-
raise "File #{config_file} does not exist" unless File.file?(config_file)
|
|
181
|
-
@config = YAML.load_file(config_file)
|
|
182
|
-
@config_file_loaded = true
|
|
183
|
-
@config.each { |k, v| send(:"#{k}=", v) }
|
|
79
|
+
# @return [Array]
|
|
80
|
+
def all_excluded_words
|
|
81
|
+
(Spoonerize.config.excluded_words + (
|
|
82
|
+
Spoonerize.config.lazy ? Spoonerize.config.lazy_words : []
|
|
83
|
+
)).map(&:downcase)
|
|
184
84
|
end
|
|
185
85
|
|
|
186
86
|
private
|
|
@@ -191,7 +91,7 @@ module Spoonerize
|
|
|
191
91
|
# through the end of the word.
|
|
192
92
|
def flip_words(word, idx) # :nodoc:
|
|
193
93
|
return word if excluded?(idx)
|
|
194
|
-
bumper = Bumper.new(idx, words.size, reverse
|
|
94
|
+
bumper = Bumper.new(idx, words.size, Spoonerize.config.reverse)
|
|
195
95
|
bumper.bump while excluded?(bumper.value)
|
|
196
96
|
words[bumper.value].match(consonants).to_s + word.match(vowels).to_s
|
|
197
97
|
end
|
|
@@ -217,16 +117,18 @@ module Spoonerize
|
|
|
217
117
|
##
|
|
218
118
|
# Creates and memoizes instance of the log file.
|
|
219
119
|
def log # :nodoc:
|
|
220
|
-
@log ||= Spoonerize::Log.new(logfile_name)
|
|
120
|
+
@log ||= Spoonerize::Log.new(Spoonerize.config.logfile_name)
|
|
221
121
|
end
|
|
222
122
|
|
|
223
123
|
##
|
|
224
|
-
#
|
|
124
|
+
# The options that were passed at runtime as a string
|
|
225
125
|
def options # :nodoc:
|
|
226
126
|
[].tap do |o|
|
|
227
|
-
o << "Lazy" if lazy
|
|
228
|
-
o << "Reverse" if reverse
|
|
229
|
-
|
|
127
|
+
o << "Lazy" if Spoonerize.config.lazy
|
|
128
|
+
o << "Reverse" if Spoonerize.config.reverse
|
|
129
|
+
if Spoonerize.config.excluded_words.any?
|
|
130
|
+
o << "Exclude [#{Spoonerize.config.excluded_words.join(", ")}]"
|
|
131
|
+
end
|
|
230
132
|
o << "No Options" if o.empty?
|
|
231
133
|
end
|
|
232
134
|
end
|
data/lib/spoonerize/version.rb
CHANGED
data/lib/spoonerize.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "spoonerize/config"
|
|
2
4
|
require_relative "spoonerize/spoonerism"
|
|
3
5
|
require_relative "spoonerize/bumper"
|
|
4
6
|
require_relative "spoonerize/version"
|
|
@@ -9,12 +11,57 @@ require_relative "spoonerize/cli"
|
|
|
9
11
|
# The main namespace for the gem.
|
|
10
12
|
module Spoonerize
|
|
11
13
|
##
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
+
# Has the config file been loaded?
|
|
15
|
+
@config_file_loaded = false
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
##
|
|
20
|
+
# Method for accessing the configuration.
|
|
21
|
+
#
|
|
22
|
+
# @return [Spoonerize::Config]
|
|
23
|
+
def config
|
|
24
|
+
@config || reset_config
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Reset all configuration values to their defaults.
|
|
29
|
+
#
|
|
30
|
+
# @return [Spoonerize::Config]
|
|
31
|
+
def reset_config
|
|
32
|
+
@config_file_loaded = false
|
|
33
|
+
@config = Spoonerize::Config.new
|
|
34
|
+
end
|
|
14
35
|
|
|
15
36
|
##
|
|
16
|
-
#
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
37
|
+
# Allows for configuration via a block. Useful when making config files.
|
|
38
|
+
#
|
|
39
|
+
# @example
|
|
40
|
+
# Spoonerize.configure { |s| s.lazy = true }
|
|
41
|
+
def configure
|
|
42
|
+
yield config
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
##
|
|
46
|
+
# Has a config file been loaded?
|
|
47
|
+
#
|
|
48
|
+
# @return [Boolean]
|
|
49
|
+
def config_file_loaded?
|
|
50
|
+
@config_file_loaded
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
##
|
|
54
|
+
# Loads a config file.
|
|
55
|
+
#
|
|
56
|
+
# @param [String] file
|
|
57
|
+
#
|
|
58
|
+
# @return [String] file
|
|
59
|
+
def load_config_file(config_file)
|
|
60
|
+
::File.expand_path(config_file).tap do |file|
|
|
61
|
+
raise "File #{file} does not exist." unless ::File.file?(file)
|
|
62
|
+
|
|
63
|
+
@config_file_loaded = true
|
|
64
|
+
load file
|
|
65
|
+
end
|
|
66
|
+
end
|
|
20
67
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spoonerize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Gray
|
|
@@ -93,10 +93,10 @@ files:
|
|
|
93
93
|
- Rakefile
|
|
94
94
|
- _config.yml
|
|
95
95
|
- bin/spoonerize
|
|
96
|
-
- lib/config/lazy_words.yml
|
|
97
96
|
- lib/spoonerize.rb
|
|
98
97
|
- lib/spoonerize/bumper.rb
|
|
99
98
|
- lib/spoonerize/cli.rb
|
|
99
|
+
- lib/spoonerize/config.rb
|
|
100
100
|
- lib/spoonerize/log.rb
|
|
101
101
|
- lib/spoonerize/spoonerism.rb
|
|
102
102
|
- lib/spoonerize/version.rb
|
data/lib/config/lazy_words.yml
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#=================================================================#
|
|
2
|
-
# File: lazy_words.yml #
|
|
3
|
-
# Description: Words to be excluded when "lazy" mode is enabled #
|
|
4
|
-
# #
|
|
5
|
-
# Author: Evan Gray #
|
|
6
|
-
#=================================================================#
|
|
7
|
-
|
|
8
|
-
- i
|
|
9
|
-
- a
|
|
10
|
-
- an
|
|
11
|
-
- and
|
|
12
|
-
- in
|
|
13
|
-
- of
|
|
14
|
-
- the
|
|
15
|
-
- my
|
|
16
|
-
- your
|
|
17
|
-
- his
|
|
18
|
-
- her
|
|
19
|
-
- him
|
|
20
|
-
- hers
|
|
21
|
-
- to
|
|
22
|
-
- is
|