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
# File lib/poefy/db_type.rb, line 19 def self.console @@console ||= false end
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
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
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
# 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
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
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
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
Find the root of the directory tree.
# File lib/poefy/self.rb, line 32 def root File.expand_path('../../../', __FILE__) end
# File lib/poefy/version.rb, line 20 def self.version_date '2017-11-05' end
# 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