module Poefy

Code for interfacing with the 'conditional_sample' gem.

Poefy exception hierarchy. These errors have short messages for developers using the gem, and longer

messages for end users who will be using the bin through the console.

If accessing through a console, all these errors are cause to exit.

Base internals for the Poem class.

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

Class methods for Poefy module.

The current version number and date.

Public Class Methods

console() click to toggle source
# File lib/poefy/db_type.rb, line 19
def self.console
  @@console ||= false
end
console=(bool) click to toggle source

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

# File lib/poefy/db_type.rb, line 16
def self.console= bool
  @@console = !!bool
end
corpora() click to toggle source

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

# File lib/poefy/self.rb, line 13
def corpora
  Poefy::Database.list
end
Also aliased as: tables, databases
corpora_with_desc() click to toggle source

Same, but with the description of the corpus too.

# File lib/poefy/self.rb, line 20
def corpora_with_desc
  Poefy::Database.list_with_desc
end
database_type(create_file = true) click to toggle source
# 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) click to toggle source

View and amend the database type in the 'settings' file.

# 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
databases()
Alias for: corpora
databases_with_desc()
Alias for: corpora_with_desc
poetic_forms() click to toggle source

Array of all names of poetic forms.

# 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) click to toggle source

Requires the chosen database interface gem.

# 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
root() click to toggle source

Find the root of the directory tree.

# File lib/poefy/self.rb, line 32
def root
  File.expand_path('../../../', __FILE__)
end
tables()
Alias for: corpora
tables_with_desc()
Alias for: corpora_with_desc
version_date() click to toggle source
# File lib/poefy/version.rb, line 20
def self.version_date
  '2017-11-05'
end
version_number() click to toggle source
# 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