poefy 0.6.1 → 1.0.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.
@@ -16,7 +16,7 @@ module Poefy
16
16
  # Generate specific poem types.
17
17
  def poem poetic_form = @poetic_form
18
18
 
19
- if !@db.exists?
19
+ if !@corpus.exists?
20
20
  return handle_error 'ERROR: Database does not yet exist', nil
21
21
  end
22
22
 
@@ -59,28 +59,6 @@ module Poefy
59
59
  output
60
60
  end
61
61
 
62
- # Get all rhyming lines for the word.
63
- def rhymes word, key = nil
64
- return nil if word.nil?
65
- sproc = @db.db.prepare %Q[
66
- SELECT rhyme, final_word, syllables, line
67
- FROM lines
68
- WHERE rhyme = ?
69
- ORDER BY rhyme, final_word, syllables, line
70
- ]
71
- output = word.to_phrase.rhymes.keys.map do |rhyme|
72
- sproc.reset!
73
- sproc.bind_param(1, rhyme)
74
- sproc.execute.to_a
75
- end.flatten
76
- sproc.close
77
- if !key.nil? and %w[rhyme final_word syllables line].include?(key)
78
- output.map!{ |i| i[key] }
79
- end
80
- output
81
- end
82
-
83
-
84
62
  private
85
63
 
86
64
  # Use the constraints in 'poetic_form' to generate a poem.
@@ -204,7 +182,7 @@ module Poefy
204
182
  # Loop through each rhyme group to find lines that satisfy the conditions.
205
183
  distinct_line_conds.each do |rhyme_letter, line_conds|
206
184
 
207
- # The conditions that will be passed to '#conditional_selection'.
185
+ # The conditions that will be passed to '#conditional_sample'.
208
186
  # This is an array of procs, one for each line.
209
187
  conditions = line_conds.map do |cond|
210
188
  proc { |arr, elem| diff_end(arr, elem) and validate_line(elem, cond)}
@@ -221,7 +199,7 @@ module Poefy
221
199
  # If all the lines include a 'syllable' condition,
222
200
  # then we can specify to only query for matching lines.
223
201
  min_max = syllable_min_max line_conds
224
- rhymes = @db.sproc_rhymes_all!(line_conds.count, min_max)
202
+ rhymes = @corpus.rhymes_by_count(line_conds.count, min_max)
225
203
 
226
204
  # Get just the rhyme part of the hash.
227
205
  rhymes = rhymes.map{ |i| i['rhyme'] }
@@ -306,7 +284,7 @@ module Poefy
306
284
  # (In a reasonable time-frame)
307
285
  def try_rhyme conditions, rhyme, syllable_min_max = nil, regex_all = nil
308
286
  output = []
309
- lines = @db.sproc_lines_all!(rhyme, syllable_min_max)
287
+ lines = @corpus.lines_by_rhyme(rhyme, syllable_min_max)
310
288
 
311
289
  # To reduce the number of permutations, reject lines
312
290
  # that do not match any of the lines regex.
@@ -314,7 +292,7 @@ module Poefy
314
292
 
315
293
  begin
316
294
  Timeout::timeout(2) do
317
- output = conditional_selection(lines.shuffle, conditions)
295
+ output = lines.shuffle.conditional_sample(conditions)
318
296
  end
319
297
  rescue
320
298
  output = []
@@ -13,13 +13,21 @@ module Poefy
13
13
  private
14
14
 
15
15
  def handle_error msg, return_value = nil
16
- if @console
16
+ if Poefy.console
17
17
  STDERR.puts msg
18
18
  exit 1
19
19
  end
20
20
  return_value
21
21
  end
22
22
 
23
+ def raise_error msg
24
+ if Poefy.console
25
+ STDERR.puts msg
26
+ exit 1
27
+ end
28
+ raise msg
29
+ end
30
+
23
31
  end
24
32
 
25
33
  end
@@ -2,38 +2,42 @@
2
2
  # Encoding: UTF-8
3
3
 
4
4
  ################################################################################
5
- # Base internals for the PoefyGen class.
5
+ # Base internals for the Poem class.
6
6
  ################################################################################
7
7
 
8
8
  module Poefy
9
9
 
10
- module PoefyGenBase
10
+ module PoemBase
11
11
 
12
- attr_reader :console, :db, :local, :overwrite
12
+ attr_reader :corpus, :local, :overwrite
13
13
 
14
14
  def initialize db_name, options = {}
15
15
  handle_options options
16
- @db = Poefy::Database.new get_database_file(db_name.to_s), @console
16
+ @corpus = Poefy::Database.new db_name, @local
17
17
  end
18
18
 
19
19
  # Make a database using the given lines.
20
- def make_database input, overwrite = @overwrite
20
+ def make_database input, description = nil, overwrite = @overwrite
21
21
  lines = validate_lines input
22
- lines.map(&:strip!)
23
- @db.close if @db
22
+ lines.map! do |line|
23
+ line.force_encoding('utf-8')
24
+ .gsub("\u00A0", ' ')
25
+ .strip
26
+ end
27
+ @corpus.close if @corpus
24
28
  if overwrite
25
- @db.make_new! lines
29
+ @corpus.make_new! lines, description
26
30
  else
27
- @db.make_new lines
31
+ @corpus.make_new lines, description
28
32
  end
29
33
  end
30
- def make_database! input
31
- make_database input, true
34
+ def make_database! input, description = nil
35
+ make_database input, description, true
32
36
  end
33
37
 
34
38
  # Close the database.
35
39
  def close
36
- @db.close
40
+ @corpus.close
37
41
  end
38
42
 
39
43
  # Validate the lines. Arg could be a filename,
@@ -44,28 +48,13 @@ module Poefy
44
48
  lines = File.exists?(input.to_s) ? File.read(input) : input
45
49
 
46
50
  # If lines is not an array, assume string and split on newlines.
47
- lines = lines.respond_to?(:each) ? lines : lines.split("\n")
48
- lines
51
+ lines.respond_to?(:each) ? lines : lines.split("\n")
49
52
  end
50
53
 
51
54
  private
52
55
 
53
- # Find the correct database file.
54
- # If local, just use the value.
55
- # Else, use the database in /data/ directory.
56
- def get_database_file database_name
57
- if @local
58
- database_name
59
- else
60
- path = File.expand_path('../../../data', __FILE__)
61
- file = File.basename(database_name, '.db')
62
- path + '/' + file + '.db'
63
- end
64
- end
65
-
66
56
  # Handle the optional initialize options hash.
67
57
  def handle_options options
68
- @console = options[:console] || false
69
58
  @overwrite = options[:overwrite] || false
70
59
  @local = options[:local] || false
71
60
  @poetic_form = {}
@@ -116,15 +105,6 @@ module Poefy
116
105
  output
117
106
  end
118
107
 
119
- # Handle error message. Quit the program if called from console.
120
- def handle_error msg
121
- if @console
122
- STDERR.puts msg
123
- exit 1
124
- end
125
- nil
126
- end
127
-
128
108
  end
129
109
 
130
110
  end
@@ -90,7 +90,7 @@ module Poefy
90
90
  # Compare each other rhyme tag, order by closeness.
91
91
  found_rhyme = line[:rhyme_tags].first
92
92
  if line[:rhyme_tags].length > 1
93
- lines.by_distance(index).each do |i|
93
+ lines.sort_by_distance_from_index(index).each do |i|
94
94
  i[:rhyme_tags].each do |tag|
95
95
  if line[:rhyme_tags].include?(tag)
96
96
  found_rhyme = tag
@@ -357,7 +357,6 @@ module Poefy
357
357
  output.reject!{ |k| k <= 0 }
358
358
 
359
359
  # Return sorted hash.
360
- # ToDo: Doesn't need to be sorted in final code.
361
360
  sort_hash output
362
361
  end
363
362
 
data/lib/poefy/self.rb CHANGED
@@ -1,21 +1,39 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: UTF-8
3
-
4
- ################################################################################
5
- # Class methods for Poefy module.
6
- ################################################################################
7
-
8
- module Poefy
9
-
10
- # Array of all '.db' files in /data/.
11
- # Do not include databases used for testing.
12
- def self.all_databases
13
- path = File.expand_path('../../../data', __FILE__)
14
- Dir["#{path}/*.db"].map do |i|
15
- File.basename(i, '.db')
16
- end.reject{ |i| i.start_with?('spec_') }
17
- end
18
-
19
- end
20
-
21
- ################################################################################
1
+ #!/usr/bin/env ruby
2
+ # Encoding: UTF-8
3
+
4
+ ################################################################################
5
+ # Class methods for Poefy module.
6
+ ################################################################################
7
+
8
+ module Poefy
9
+ class << self
10
+
11
+ # Array of all databases (SQLite) or tables (Postgres)
12
+ # Does not include databases used for testing.
13
+ def corpora
14
+ Poefy::Database.list
15
+ end
16
+ alias_method :tables, :corpora
17
+ alias_method :databases, :corpora
18
+
19
+ # Same, but with the description of the corpus too.
20
+ def corpora_with_desc
21
+ Poefy::Database.list_with_desc
22
+ end
23
+ alias_method :tables_with_desc, :corpora_with_desc
24
+ alias_method :databases_with_desc, :corpora_with_desc
25
+
26
+ # Array of all names of poetic forms.
27
+ def poetic_forms
28
+ PoeticForms::POETIC_FORMS.keys.reject { |i| i == :default }
29
+ end
30
+
31
+ # Find the root of the directory tree.
32
+ def root
33
+ File.expand_path('../../../', __FILE__)
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ ################################################################################
@@ -45,7 +45,7 @@ module Poefy
45
45
  # This will not work for floats.
46
46
  # It will also break emoticons, but GIGO.
47
47
  def humanize_instr text
48
- output = text
48
+ output = text.dup
49
49
  loop do
50
50
  num = output[/\d+/]
51
51
  break if not num
data/lib/poefy/version.rb CHANGED
@@ -1,29 +1,26 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: UTF-8
3
-
4
- ################################################################################
5
- # The current version number and date.
6
- ################################################################################
7
-
8
- module Poefy
9
-
10
- def self.version_number
11
- Gem::Version.new VERSION::STRING
12
- end
13
-
14
- def self.version_date
15
- '2017-06-19'
16
- end
17
-
18
- module VERSION
19
- MAJOR = 0
20
- MINOR = 6
21
- TINY = 1
22
- PRE = nil
23
-
24
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
25
- end
26
-
27
- end
28
-
29
- ################################################################################
1
+ #!/usr/bin/env ruby
2
+ # Encoding: UTF-8
3
+
4
+ ################################################################################
5
+ # The current version number and date.
6
+ ################################################################################
7
+
8
+ module Poefy
9
+
10
+ def self.version_number
11
+ major = 1
12
+ minor = 0
13
+ tiny = 0
14
+ pre = nil
15
+
16
+ string = [major, minor, tiny, pre].compact.join('.')
17
+ Gem::Version.new string
18
+ end
19
+
20
+ def self.version_date
21
+ '2017-10-02'
22
+ end
23
+
24
+ end
25
+
26
+ ################################################################################
data/lib/poefy.rb CHANGED
@@ -2,47 +2,42 @@
2
2
  # Encoding: UTF-8
3
3
 
4
4
  ################################################################################
5
- # Line-based, used only to rearrange lines of text, not create new lines.
6
- # Also uses 'wordfilter' to get rid of yucky words.
7
- #
8
- # https://en.wikipedia.org/wiki/Category:Western_medieval_lyric_forms
9
- # https://en.wikipedia.org/wiki/Virelai
10
- # https://en.wikipedia.org/wiki/List_of_compositions_by_Guillaume_de_Machaut#Virelais
5
+ # Create a database from text lines.
6
+ # Read the database to generate poetry.
11
7
  ################################################################################
12
8
 
9
+ require 'conditional_sample'
13
10
  require 'ruby_rhymes'
14
11
  require 'wordfilter'
15
12
  require 'humanize'
16
- require 'tempfile'
17
- require 'sqlite3'
18
13
  require 'timeout'
14
+ require 'yaml'
19
15
 
20
16
  require_relative 'poefy/version.rb'
21
17
  require_relative 'poefy/self.rb'
22
- require_relative 'poefy/poefy_gen_base.rb'
18
+ require_relative 'poefy/db_type.rb'
19
+ require_relative 'poefy/poem_base.rb'
23
20
  require_relative 'poefy/generation.rb'
24
21
  require_relative 'poefy/poetic_forms.rb'
25
22
  require_relative 'poefy/poetic_form_from_text.rb'
26
23
  require_relative 'poefy/string_manipulation.rb'
27
24
  require_relative 'poefy/handle_error.rb'
28
25
  require_relative 'poefy/database.rb'
29
- require_relative 'poefy/conditional_satisfaction.rb'
26
+ require_relative 'poefy/conditional_sample.rb'
30
27
  require_relative 'poefy/core_extensions/array.rb'
31
28
 
32
29
  ################################################################################
33
30
 
34
- # Create a database from text lines.
35
- # Read the database to generate poetry.
36
31
  module Poefy
37
32
 
38
- class PoefyGen
33
+ class Poem
39
34
 
40
- include Poefy::PoefyGenBase
35
+ include Poefy::PoemBase
41
36
  include Poefy::Generation
42
37
  include Poefy::PoeticForms
43
38
  include Poefy::PoeticFormFromText
44
39
  include Poefy::StringManipulation
45
- include Poefy::ConditionalSatisfaction
40
+ include Poefy::ConditionalSample
46
41
  include Poefy::HandleError
47
42
 
48
43
  end
data/poefy.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ['nossidge@gmail.com']
11
11
 
12
12
  s.summary = %q{Create rhyming poetry by rearranging lines of text}
13
- s.description = %q{Create poems from an input text file, by generating and querying a SQLite database describing each line. Poems are created using a template to select lines from the database, according to closing rhyme, syllable count, and regex matching.}
13
+ s.description = %q{Create poems from an input text file, by generating and querying a SQLite or PostgreSQL database describing each line. Poems are created using a template to select lines from the database, according to closing rhyme, syllable count, and regex matching.}
14
14
  s.homepage = 'https://github.com/nossidge/poefy'
15
15
 
16
16
  s.version = Poefy.version_number
@@ -23,12 +23,23 @@ Gem::Specification.new do |s|
23
23
  s.require_paths = ['lib']
24
24
  s.bindir = 'bin'
25
25
 
26
+ s.post_install_message = %q{---
27
+ Thanks for installing poefy.
28
+ Please also install one of the below gems:
29
+ $ gem install poefy-pg
30
+ $ gem install poefy-sqlite
31
+ Then run this command to generate the included corpora:
32
+ $ poefy_make
33
+ ---}.split("\n").map{ |i| i.sub(' ','') }.join("\n")
34
+
26
35
  s.add_development_dependency('bundler', '~> 1.13')
27
36
  s.add_development_dependency('rake', '~> 10.0')
28
37
  s.add_development_dependency('rspec', '~> 3.0')
38
+ s.add_development_dependency('poefy-sqlite3', '~> 0.1')
39
+ s.add_development_dependency('poefy-pg', '~> 0.1')
29
40
 
30
- s.add_runtime_dependency('sqlite3', '~> 1.3', '>= 1.3.13')
31
- s.add_runtime_dependency('ruby_rhymes', '~> 0.1', '>= 0.1.2')
32
- s.add_runtime_dependency('wordfilter', '~> 0.2', '>= 0.2.6')
33
- s.add_runtime_dependency('humanize', '~> 1.4', '>= 1.4.0')
41
+ s.add_runtime_dependency('conditional_sample', '~> 1.0', '>= 1.0.0')
42
+ s.add_runtime_dependency('ruby_rhymes', '~> 0.1', '>= 0.1.2')
43
+ s.add_runtime_dependency('wordfilter', '~> 0.2', '>= 0.2.6')
44
+ s.add_runtime_dependency('humanize', '~> 1.4', '>= 1.4.0')
34
45
  end
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: UTF-8
3
+
4
+ ################################################################################
5
+
6
+ describe Poefy::Poem, "-- Unit tests" do
7
+
8
+ describe "#transform_string_regex" do
9
+
10
+ # Singleton which includes the method.
11
+ # Make the private methods public.
12
+ let(:obj) do
13
+ class Sing
14
+ include Poefy::PoeticForms
15
+ include Poefy::StringManipulation
16
+ public *private_instance_methods
17
+ end.new
18
+ end
19
+
20
+ describe "using rhyme string 'aabba'" do
21
+ input_and_output = [
22
+ ['^[^e]*$',
23
+ {
24
+ 1=>/^[^e]*$/,
25
+ 2=>/^[^e]*$/,
26
+ 3=>/^[^e]*$/,
27
+ 4=>/^[^e]*$/,
28
+ 5=>/^[^e]*$/
29
+ }],
30
+ ['[/(?=^[A-Z])(?=^[^eE]*$)/,/^[^eE]*$/,/^[^eE]*$/,/^[^eE]*$/,/^[^eE]*$/]',
31
+ {
32
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
33
+ 2=>/^[^eE]*$/,
34
+ 3=>/^[^eE]*$/,
35
+ 4=>/^[^eE]*$/,
36
+ 5=>/^[^eE]*$/
37
+ }],
38
+ ['{1=>/(?=^[A-Z])(?=^[^eE]*$)/,2=>/^[^eE]*$/,3=>/^[^eE]*$/,4=>/^[^eE]*$/,5=>/^[^eE]*$/}',
39
+ {
40
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
41
+ 2=>/^[^eE]*$/,
42
+ 3=>/^[^eE]*$/,
43
+ 4=>/^[^eE]*$/,
44
+ 5=>/^[^eE]*$/
45
+ }],
46
+ ['{0=>/^[^eE]*$/,1=>/(?=^[A-Z])(?=^[^eE]*$)/}',
47
+ {
48
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
49
+ 2=>/^[^eE]*$/,
50
+ 3=>/^[^eE]*$/,
51
+ 4=>/^[^eE]*$/,
52
+ 5=>/^[^eE]*$/
53
+ }],
54
+ ['{1=>/(?=^[A-Z])(?=^[^eE]*$)/,2=>/^[^eE]*$/,3=>/^[^eE]*$/,5=>/^[^eE]*$/}',
55
+ {
56
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
57
+ 2=>/^[^eE]*$/,
58
+ 3=>/^[^eE]*$/,
59
+ 4=>nil,
60
+ 5=>/^[^eE]*$/
61
+ }],
62
+ ['{1=>/(?=^[A-Z])(?=^[^eE]*$)/,4=>/^[^eE]*$/}',
63
+ {
64
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
65
+ 2=>nil,
66
+ 3=>nil,
67
+ 4=>/^[^eE]*$/,
68
+ 5=>nil
69
+ }],
70
+ ['{1=>/(?=^[A-Z])(?=^[^eE]*$)/,2=>/^[^eE]*$/,3=>/^[^eE]*$/,-1=>/^[^eE]*$/,-2=>/^[^eE]*$/}',
71
+ {
72
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
73
+ 2=>/^[^eE]*$/,
74
+ 3=>/^[^eE]*$/,
75
+ 4=>/^[^eE]*$/,
76
+ 5=>/^[^eE]*$/
77
+ }]
78
+ ]
79
+ input_and_output.each do |pair|
80
+ it "regex: #{pair.first}" do
81
+ out = obj.transform_string_regex(pair.first, 'aabba')
82
+ again = obj.transform_string_regex(out, 'aabba')
83
+ expect(out).to eq pair.last
84
+ expect(again).to eq out
85
+ expect(again).to eq pair.last
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ ##############################################################################
92
+
93
+ describe "#transform_string_syllable" do
94
+
95
+ # Singleton which includes the method.
96
+ # Make the private methods public.
97
+ let(:obj) do
98
+ class Sing
99
+ include Poefy::PoeticForms
100
+ include Poefy::StringManipulation
101
+ public *private_instance_methods
102
+ end.new
103
+ end
104
+ describe "using rhyme string 'aabba'" do
105
+ input_and_output = [
106
+ ['10',
107
+ {1=>10,2=>10,3=>10,4=>10,5=>10}],
108
+ ['9,10,11',
109
+ {1=>[9,10,11],2=>[9,10,11],3=>[9,10,11],4=>[9,10,11],5=>[9,10,11]}],
110
+ ['[8,8,5,5,8]',
111
+ {1=>8,2=>8,3=>5,4=>5,5=>8}],
112
+ ['[[8,9],[8,9],[4,5,6],[4,5,6],[8,9]]',
113
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
114
+ ['{1:8,2:8,3:5,4:5,5:8}',
115
+ {1=>8,2=>8,3=>5,4=>5,5=>8}],
116
+ ['{1:8,2:8,3:5,5:8}',
117
+ {1=>8,2=>8,3=>5,4=>0,5=>8}],
118
+ ['{0:99,1:8,2:8,3:5,5:8}',
119
+ {1=>8,2=>8,3=>5,4=>99,5=>8}],
120
+ ['{1:[8,9],2:[8,9],3:[4,5,6],4:[4,5,6],5:[8,9]}',
121
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
122
+ ['{1:[8,9],2:[8,9],3:[4,5,6],5:[8,9]}',
123
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>0,5=>[8,9]}],
124
+ ['{0:99,1:[8,9],2:[8,9],3:[4,5,6],5:[8,9]}',
125
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>99,5=>[8,9]}],
126
+ ['{0:[8,9],3:[4,5,6],4:[4,5,6]}',
127
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
128
+ ['{1:8,5:8}',
129
+ {1=>8,2=>0,3=>0,4=>0,5=>8}],
130
+ ['{1:8,2:8,3:5,-2:5,-1:8}',
131
+ {1=>8,2=>8,3=>5,4=>5,5=>8}]
132
+ ]
133
+ input_and_output.each do |pair|
134
+ it "syllable: #{pair.first}" do
135
+ rhyme = obj.tokenise_rhyme('aabba')
136
+ out = obj.transform_string_syllable(pair.first, 'aabba')
137
+ again = obj.transform_string_syllable(out, 'aabba')
138
+ expect(out).to eq pair.last
139
+ expect(again).to eq out
140
+ expect(again).to eq pair.last
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ ##############################################################################
147
+
148
+ describe "private method #poetic_form_from_text" do
149
+
150
+ # Singleton which includes the method.
151
+ # Make the private methods public.
152
+ let(:obj) do
153
+ class Sing
154
+ include Poefy::PoeticFormFromText
155
+ include Poefy::StringManipulation
156
+ public *private_instance_methods
157
+ end.new
158
+ end
159
+
160
+ it "'80' should rhyme with 'weighty'" do
161
+ lines = ["Lorem ipsum dolor weighty", "Lorem ipsum dolor 80"]
162
+ form = obj.poetic_form_from_text(lines)
163
+ expect(form[:rhyme].uniq.count).to be 1
164
+ end
165
+ it "'80' should not rhyme with 'shoe'" do
166
+ lines = ["Lorem ipsum dolor shoe", "Lorem ipsum dolor 80"]
167
+ form = obj.poetic_form_from_text(lines)
168
+ expect(form[:rhyme].uniq.count).to_not be 1
169
+ end
170
+ it "'2' should rhyme with 'shoe'" do
171
+ lines = ["Lorem ipsum dolor shoe", "Lorem ipsum dolor 2"]
172
+ form = obj.poetic_form_from_text(lines)
173
+ expect(form[:rhyme].uniq.count).to be 1
174
+ end
175
+ it "'2' should not rhyme with 'weighty'" do
176
+ lines = ["Lorem ipsum dolor weighty", "Lorem ipsum dolor 2"]
177
+ form = obj.poetic_form_from_text(lines)
178
+ expect(form[:rhyme].uniq.count).to_not be 1
179
+ end
180
+ it "'wind' should rhyme with 'sinned'" do
181
+ lines = ["A mighty wind", "A whitey sinned"]
182
+ form = obj.poetic_form_from_text(lines)
183
+ expect(form[:rhyme].uniq.count).to be 1
184
+ end
185
+ it "'wind' should rhyme with 'mind'" do
186
+ lines = ["A mighty wind", "A flighty mind"]
187
+ form = obj.poetic_form_from_text(lines)
188
+ expect(form[:rhyme].uniq.count).to be 1
189
+ end
190
+ it "'wind' should not rhyme with 'drunk'" do
191
+ lines = ["A mighty wind", "A fighty drunk"]
192
+ form = obj.poetic_form_from_text(lines)
193
+ expect(form[:rhyme].uniq.count).to_not be 1
194
+ end
195
+ end
196
+
197
+ end
198
+
199
+ ################################################################################
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
+ require 'tempfile'
5
+
4
6
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
7
  require 'poefy'
6
8