Module: Poefy

Defined in:
lib/poefy/self.rb,
lib/poefy.rb,
lib/poefy/db_type.rb,
lib/poefy/version.rb,
lib/poefy/database.rb,
lib/poefy/poem_base.rb,
lib/poefy/exceptions.rb,
lib/poefy/generation.rb,
lib/poefy/poetic_forms.rb,
lib/poefy/conditional_sample.rb,
lib/poefy/string_manipulation.rb,
lib/poefy/core_extensions/array.rb,
lib/poefy/poetic_form_from_text.rb

Overview

Read a song lyric file, output a poetic_form that matches its form.

Defined Under Namespace

Modules: ConditionalSample, CoreExtensions, Generation, PoemBase, PoeticFormFromText, PoeticForms, StringManipulation Classes: Database, DatabaseError, Error, GenerationError, InputError, MissingDBInterface, MissingDatabase, MissingFormOrRhyme, NotEnoughData, Poem, RegexError, RhymeError, StructureInvalid, SyllableError

Class Method Summary collapse

Class Method Details

.consoleObject



19
20
21
# File 'lib/poefy/db_type.rb', line 19

def self.console
  @@console ||= false
end

.console=(bool) ⇒ Object

Are we running this through the console? (Or as a Ruby library?)



16
17
18
# File 'lib/poefy/db_type.rb', line 16

def self.console= bool
  @@console = !!bool
end

.corporaObject Also known as: tables, databases

Array of all databases (SQLite) or tables (Postgres) Does not include databases used for testing.



13
14
15
# File 'lib/poefy/self.rb', line 13

def corpora
  Poefy::Database.list
end

.corpora_with_descObject Also known as: tables_with_desc, databases_with_desc

Same, but with the description of the corpus too.



20
21
22
# File 'lib/poefy/self.rb', line 20

def corpora_with_desc
  Poefy::Database.list_with_desc
end

.database_type(create_file = true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/poefy/db_type.rb', line 32

def self.database_type create_file = true
  @@database_type ||= nil
  return @@database_type if @@database_type
  settings_file = Poefy.root + '/settings.yml'
  if not File.exists?(settings_file)
    return nil if !create_file
    Poefy.database_type = 'pg'
  end
  @@database_type = YAML::load_file(settings_file)['database']
end

.database_type=(db_name) ⇒ Object

View and amend the database type in the ‘settings’ file.



24
25
26
27
28
29
30
31
# File 'lib/poefy/db_type.rb', line 24

def self.database_type= db_name
  settings_file = Poefy.root + '/settings.yml'
  File.open(settings_file, 'w') do |file|
    hsh = {'database' => db_name}
    file.write hsh.to_yaml
  end
  @@database_type = nil
end

.poetic_formsObject

Array of all names of poetic forms.



27
28
29
# File 'lib/poefy/self.rb', line 27

def poetic_forms
  PoeticForms::POETIC_FORMS.keys.reject { |i| i == :default }
end

.require_db(db_interface_gem = nil) ⇒ Object

Requires the chosen database interface gem.



44
45
46
47
48
49
50
51
52
53
# File 'lib/poefy/db_type.rb', line 44

def self.require_db db_interface_gem = nil
  begin
    @@database_type = db_interface_gem if db_interface_gem
    require 'poefy/' + (db_interface_gem || Poefy.database_type)

  # Replace with custom exception.
  rescue LoadError
    raise Poefy::MissingDBInterface
  end
end

.rootObject

Find the root of the directory tree.



32
33
34
# File 'lib/poefy/self.rb', line 32

def root
  File.expand_path('../../../', __FILE__)
end

.version_dateObject



20
21
22
# File 'lib/poefy/version.rb', line 20

def self.version_date
  '2017-11-05'
end

.version_numberObject



10
11
12
13
14
15
16
17
18
# File 'lib/poefy/version.rb', line 10

def self.version_number
  major = 1
  minor = 1
  tiny  = 1
  pre   = nil

  string = [major, minor, tiny, pre].compact.join('.')
  Gem::Version.new string
end