Class: DbFile

Inherits:
Object
  • Object
show all
Defined in:
lib/active_csv/db_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_name) ⇒ DbFile

Returns a new instance of DbFile.



4
5
6
# File 'lib/active_csv/db_file.rb', line 4

def initialize(_name)
	@name = _name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/active_csv/db_file.rb', line 2

def name
  @name
end

Instance Method Details

#create_db_fileObject



22
23
24
# File 'lib/active_csv/db_file.rb', line 22

def create_db_file
	CSV.open(name,'w')
end

#csv_contentObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/active_csv/db_file.rb', line 7

def csv_content
	csv_rows = Array.new
	if !file_exists?
		create_db_file
	end
	CSV.read(name).each do |row|
			csv_rows << row
	end
	csv_rows
end

#field_valuesObject



26
27
28
# File 'lib/active_csv/db_file.rb', line 26

def field_values
	ActiveCSV.field_values
end

#file_exists?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/active_csv/db_file.rb', line 18

def file_exists?
	File.exists?(name)
end