dunmanifestin 0.0.9 → 0.1.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
  SHA1:
3
- metadata.gz: b2022c4e781ac963dc63ffe5494b131ee1d732d1
4
- data.tar.gz: cac7e12fe381905c8f3e2ace2ed76cef9110a40a
3
+ metadata.gz: f67796f5a0ba25692e7feeaeff6d9cbc95355d52
4
+ data.tar.gz: 00f7900e4f8901c372dfddd8edf4b7a68fe2a7a2
5
5
  SHA512:
6
- metadata.gz: 0107f2ec4ca3ef198cd22655268c20af70320d888235e51c306e902b93ea219b3b52bd2806268f09df5c9fd091520389f89311f857b272e559970812db47643f
7
- data.tar.gz: a8c0314dcb3657eeb1bce8fbfe3351429c59e5aa5653465c60f6942a87aa41863c3e3c3f0cb2a7ade86963b3ac767aafca12ef0dea7142e8724eb4ea8e770a41
6
+ metadata.gz: 4797de63956082595b5510ff86d3cd86c12e7f58decc7bafd3294bd5124c0cb7538a1636659b725bc28b461ae63b6bdc575ef52ee5f9063b26c975bc79ad7184
7
+ data.tar.gz: cfb20a23393c3ed906690fb789efbbed5797838f257a7260fbdf1375bf4fd1e830512d91fdd318f64b72d675f05493de95c51433b5a106b70a3b0720d682318b
@@ -8,9 +8,9 @@ user_demands = Trollop::options do
8
8
  opt :interactive, "Use an interactive command prompt", short: '-i'
9
9
  opt :count, "Specify how many lines of output to generate at once", type: :integer, short: '-n'
10
10
  opt :copy, "Copies manifestation into your clipboard", short: '-c'
11
- opt :genre, "Specify a genre by filepath, e.g. '-g lists/scifi/'", type: :string, short: '-g', default: 'default'
11
+ opt :genre, "Specify a genre or two by filepath, e.g. '-g genres/scifi/', '-g ./genres/poetry:./genres/romantics'", type: :string, short: '-g'
12
12
  opt :phrase, "Specify a phrase or list, e.g. 'The [animal] sat on the [article]' or '[weapon]'", type: :string, short: '-p'
13
- opt :chomp, "remove the trailing newline from the output", short: '-h'
13
+ opt :chomp, "remove the trailing newline from the output", short: '-o'
14
14
  opt :file, "Read a file as the phrase", type: :string, short: '-f'
15
15
  end
16
16
 
@@ -1,51 +1,21 @@
1
+ require_relative 'phrase'
2
+ require_relative 'string'
3
+ require_relative 'palette'
4
+
1
5
  class ListLoader
6
+ DEFAULT_GENRE = File.join(*%W(#{File.dirname(__FILE__)} .. .. default-genre))
7
+
2
8
  class << self
3
- def load genre=@genre
4
- Dir[DEFAULT_GENRE].each(&method(:expose_palettes))
5
- load_genre(genre).each(&method(:expose_palettes))
9
+ def load super_genre=""
10
+ [DEFAULT_GENRE, super_genre.split(":")]
11
+ .flatten.compact.each(&method(:load_genre))
6
12
  end
7
13
 
8
14
  private
9
- PALETTE_TITLE = /^\|(.*?)\n/
10
- GAP_BETWEEN_LISTS = /\n(?=\|)/
11
- DEFAULT_GENRE = File.join(*%W(#{File.dirname(__FILE__)} .. .. default-genre ** *))
12
15
 
13
16
  def load_genre dirname
14
- Dir[File.join(dirname, '**' '*')]
15
- end
16
-
17
- def expose_palettes path
18
- File.open(path).read.split(GAP_BETWEEN_LISTS)
19
- .each &method(:expose_swatches)
20
- end
21
-
22
- def expose_swatches body
23
- list_name = body.match(PALETTE_TITLE)[1].to_s
24
-
25
- if list_name.empty?
26
- # This seems to support palettes without |explicitTitles,
27
- # Taking them from the filename, instead.
28
- list_name = Pathname.new(path).basename
29
- else
30
- # Do not include palette title as a swatch
31
- # These comments should be tests.
32
- body.gsub!(PALETTE_TITLE, '')
33
- end
34
-
35
- # This metaprogramming is mysterious to me.
36
- qlass = declare_phrase_class list_name
37
- # Where is 'list' defined?
38
- qlass.list body
39
- end
40
-
41
- def declare_phrase_class list_name
42
- name = list_name.underscore.camelize
43
- qlass = "Phrase::#{name}".constantize
44
- rescue NameError
45
- # This seems to always happen.
46
- qlass = Class.new(Phrase)
47
- Phrase.const_set name, qlass
48
- end
17
+ Dir[File.join(dirname, '**' '*')].each(&Palette.method(:expose))
18
+ end
49
19
  end
50
20
  end
51
21
 
@@ -0,0 +1,39 @@
1
+ class Palette
2
+ GAP_BETWEEN_LISTS = /\n(?=\|)/
3
+ PALETTE_TITLE = /^\|(.*?)\n/
4
+ class << self
5
+ def expose path
6
+ File.open(path).read
7
+ .split(GAP_BETWEEN_LISTS)
8
+ .each &method(:expose_swatches)
9
+ end
10
+
11
+ def expose_swatches body
12
+ list_name = body.match(PALETTE_TITLE)[1].to_s
13
+
14
+ if list_name.empty?
15
+ # This seems to support palettes without |explicitTitles,
16
+ # Taking them from the filename, instead.
17
+ list_name = Pathname.new(path).basename
18
+ else
19
+ # Do not include palette title as a swatch
20
+ # These comments should be tests.
21
+ body.gsub!(PALETTE_TITLE, '')
22
+ end
23
+
24
+ # This metaprogramming is mysterious to me.
25
+ qlass = declare_phrase_class list_name
26
+ # Where is 'list' defined?
27
+ qlass.list body
28
+ end
29
+
30
+ def declare_phrase_class list_name
31
+ name = list_name.underscore.camelize
32
+ qlass = "Phrase::#{name}".constantize
33
+ rescue NameError
34
+ # This seems to always happen.
35
+ qlass = Class.new(Phrase)
36
+ Phrase.const_set name, qlass
37
+ end
38
+ end
39
+ end
@@ -58,9 +58,7 @@ class Phrase
58
58
 
59
59
  @to_s_proc = -> {
60
60
  self.variables.each_with_index do |variable, i|
61
- inflections[i].each do |inflection|
62
- variable.send "#{inflection}!"
63
- end
61
+ inflections[i].each { |inflection| variable.inflect inflection }
64
62
  end
65
63
  template.zip(self.variables).flatten.map(&:to_s).join('')
66
64
  }
@@ -125,79 +123,32 @@ class Phrase
125
123
  def capitalize?; !!@capitalize end
126
124
  def titleize?; !!@titleize end
127
125
 
128
- def plural!
129
- @plural = true
130
-
131
- @inflection_delegates[:plural].each do |delegate|
132
- variables[delegate].plural!
133
- end
134
- self
135
- end
136
-
137
- def article!
138
- @article = true
139
-
140
- @inflection_delegates[:article].each do |delegate|
141
- variables[delegate].article!
142
- end
143
- self
144
- end
145
-
146
- def possessive!
147
- @possessive = true
148
-
149
- @inflection_delegates[:possessive].each do |delegate|
150
- variables[delegate].possessive!
151
- end
152
- self
153
- end
154
-
155
- def capitalize!
156
- @capitalize = true
157
-
158
- @inflection_delegates[:capitalize].each do |delegate|
159
- variables[delegate].capitalize!
160
- end
161
- self
162
- end
163
-
164
126
  def titleize!
165
- @titleize = true
127
+ delegates = @inflection_delegates[:capitalize]
128
+ delegates.each { |delegate| variables[delegate].capitalize! }
129
+ end
166
130
 
167
- @inflection_delegates[:capitalize].each do |delegate|
168
- variables[delegate].capitalize!
169
- end
131
+ def inflect inflection
132
+ return self unless @inflection_delegates
133
+ self.instance_variable_set("@#{inflection}", true)
134
+ return (titleize! && self) if inflection == :titleize
135
+
136
+ delegates = @inflection_delegates[inflection]
137
+ delegates.each { |delegate| variables[delegate].inflect inflection }
138
+
170
139
  self
171
140
  end
172
-
141
+
173
142
  def to_s
174
143
  render_inflections @to_s_proc.call
175
144
  end
176
145
 
177
146
  def render_inflections string
178
- if plural?
179
- string = string.pluralize if @inflection_delegates[:plural].empty?
180
- if possessive? && @inflection_delegates[:possessive].empty?
181
- if string =~ /s$/
182
- string = "#{string}'"
183
- else
184
- string = "#{string}'s"
185
- end
186
- end
187
- else
188
- #singular
189
- if article? && @inflection_delegates[:article].empty?
190
- if string =~ /^[aeiou]/i
191
- string = "an #{string}"
192
- else
193
- string = "a #{string}"
194
- end
195
- end
196
- if possessive? && @inflection_delegates[:possessive].empty?
197
- string = "#{string}'s"
198
- end
199
- end
200
-
147
+ # Good, now turn this into a stateless function.
148
+ string = string.pluralize if plural? && @inflection_delegates[:plural].empty?
149
+ string = (string =~ /s$/) ? "#{string}'" : "#{string}'s" if plural? && possessive? && @inflection_delegates[:possessive].empty?
150
+ string = "#{string}'s" if !plural? && possessive? && @inflection_delegates[:possessive].empty?
151
+ string = (string =~ /^[aeiou]/i) ? "an #{string}" : "a #{string}" if !plural? && article? && @inflection_delegates[:article].empty?
201
152
  string = string[0].capitalize + string[1 .. -1] if capitalize?
202
153
  string = string.titleize if titleize?
203
154
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dunmanifestin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - quavmo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-07 00:00:00.000000000 Z
13
+ date: 2016-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: trollop
@@ -83,6 +83,7 @@ files:
83
83
  - lib/dunmanifestin/list_loader.rb
84
84
  - lib/dunmanifestin/manifestation.rb
85
85
  - lib/dunmanifestin/member.rb
86
+ - lib/dunmanifestin/palette.rb
86
87
  - lib/dunmanifestin/phrase.rb
87
88
  - lib/dunmanifestin/string.rb
88
89
  - lib/dunmanifestin/terminator.rb
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  version: '0'
115
116
  requirements: []
116
117
  rubyforge_project:
117
- rubygems_version: 2.0.14
118
+ rubygems_version: 2.0.14.1
118
119
  signing_key:
119
120
  specification_version: 4
120
121
  summary: A verisimilitude generator.