Module: Poefy::PoefyGenBase
- Included in:
- PoefyGen
- Defined in:
- lib/poefy/poefy_gen_base.rb
Instance Attribute Summary collapse
-
#console ⇒ Object
readonly
Returns the value of attribute console.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#overwrite ⇒ Object
readonly
Returns the value of attribute overwrite.
Instance Method Summary collapse
-
#close ⇒ Object
Close the database.
- #initialize(db_name, options = {}) ⇒ Object
-
#make_database(input, overwrite = @overwrite) ⇒ Object
Make a database using the given lines.
- #make_database!(input) ⇒ Object
-
#validate_lines(input) ⇒ Object
Validate the lines.
Instance Attribute Details
#console ⇒ Object (readonly)
Returns the value of attribute console.
12 13 14 |
# File 'lib/poefy/poefy_gen_base.rb', line 12 def console @console end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
12 13 14 |
# File 'lib/poefy/poefy_gen_base.rb', line 12 def db @db end |
#local ⇒ Object (readonly)
Returns the value of attribute local.
12 13 14 |
# File 'lib/poefy/poefy_gen_base.rb', line 12 def local @local end |
#overwrite ⇒ Object (readonly)
Returns the value of attribute overwrite.
12 13 14 |
# File 'lib/poefy/poefy_gen_base.rb', line 12 def overwrite @overwrite end |
Instance Method Details
#close ⇒ Object
Close the database.
35 36 37 |
# File 'lib/poefy/poefy_gen_base.rb', line 35 def close @db.close end |
#initialize(db_name, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/poefy/poefy_gen_base.rb', line 14 def initialize db_name, = {} @db = Poefy::Database.new get_database_file(db_name.to_s), @console end |
#make_database(input, overwrite = @overwrite) ⇒ Object
Make a database using the given lines.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/poefy/poefy_gen_base.rb', line 20 def make_database input, overwrite = @overwrite lines = validate_lines input lines.map(&:strip!) @db.close if @db if overwrite @db.make_new! lines else @db.make_new lines end end |
#make_database!(input) ⇒ Object
30 31 32 |
# File 'lib/poefy/poefy_gen_base.rb', line 30 def make_database! input make_database input, true end |
#validate_lines(input) ⇒ Object
Validate the lines. Arg could be a filename,
newline delimited string, or array of lines.
41 42 43 44 45 46 47 48 49 |
# File 'lib/poefy/poefy_gen_base.rb', line 41 def validate_lines input # If the input is a file, then read it. lines = File.exists?(input.to_s) ? File.read(input) : input # If lines is not an array, assume string and split on newlines. lines = lines.respond_to?(:each) ? lines : lines.split("\n") lines end |