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.
33 34 35 |
# File 'lib/poefy/poefy_gen_base.rb', line 33 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 |
# File 'lib/poefy/poefy_gen_base.rb', line 20 def make_database input, overwrite = @overwrite @db.close if @db if overwrite @db.make_new! validate_lines input else @db.make_new validate_lines input end end |
#make_database!(input) ⇒ Object
28 29 30 |
# File 'lib/poefy/poefy_gen_base.rb', line 28 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.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/poefy/poefy_gen_base.rb', line 39 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.map(&:strip!) lines end |