Class: ActiveCsv
- Inherits:
-
Object
show all
- Includes:
- ActiveModel::Model
- Defined in:
- lib/PVLIB_Ruby/models/active_csv.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.create(csv_filepath) ⇒ Object
10
11
12
13
14
|
# File 'lib/PVLIB_Ruby/models/active_csv.rb', line 10
def self.create(csv_filepath)
new_instance = self.new
new_instance.load_data(csv_filepath)
new_instance
end
|
Instance Method Details
#load_data(csv_filepath) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/PVLIB_Ruby/models/active_csv.rb', line 24
def load_data(csv_filepath)
csv = CSV.new(File.new(csv_filepath), headers: true, header_converters: :symbol)
data = csv.shift
= nil;
index = 0;
data..each do ||
if "#{}=" == "="
if !.blank? && !data[index].blank?
= self.send(.to_sym)
if .instance_of? Array
<< data[index]
self.send("#{}=".to_sym, )
else
self.send("#{}=".to_sym, [,data[index]])
end
end
else
self.send("#{}=".to_sym, data[])
end
= unless .blank?
index = index + 1;
end
end
|
#persisted? ⇒ Boolean
16
17
18
|
# File 'lib/PVLIB_Ruby/models/active_csv.rb', line 16
def persisted?
false
end
|
#valid? ⇒ Boolean
20
21
22
|
# File 'lib/PVLIB_Ruby/models/active_csv.rb', line 20
def valid?
end
|