Class: DbFile
- Inherits:
-
Object
- Object
- DbFile
- Defined in:
- lib/active_csv/db_file.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #create_db_file ⇒ Object
- #csv_content ⇒ Object
- #field_values ⇒ Object
- #file_exists? ⇒ Boolean
-
#initialize(_name) ⇒ DbFile
constructor
A new instance of DbFile.
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
#name ⇒ Object
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_file ⇒ Object
22 23 24 |
# File 'lib/active_csv/db_file.rb', line 22 def create_db_file CSV.open(name,'w') end |
#csv_content ⇒ Object
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_values ⇒ Object
26 27 28 |
# File 'lib/active_csv/db_file.rb', line 26 def field_values ActiveCSV.field_values end |
#file_exists? ⇒ Boolean
18 19 20 |
# File 'lib/active_csv/db_file.rb', line 18 def file_exists? File.exists?(name) end |