Module: Poefy::PoefyGenBase

Included in:
PoefyGen
Defined in:
lib/poefy/poefy_gen_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#consoleObject (readonly)

Returns the value of attribute console.



12
13
14
# File 'lib/poefy/poefy_gen_base.rb', line 12

def console
  @console
end

#dbObject (readonly)

Returns the value of attribute db.



12
13
14
# File 'lib/poefy/poefy_gen_base.rb', line 12

def db
  @db
end

#localObject (readonly)

Returns the value of attribute local.



12
13
14
# File 'lib/poefy/poefy_gen_base.rb', line 12

def local
  @local
end

#overwriteObject (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

#closeObject

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, options = {}
  handle_options options
  @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