Class: Gemgento::Import
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gemgento::Import
show all
- Defined in:
- app/models/gemgento/import.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
Returns the value of attribute header_row.
24
25
26
|
# File 'app/models/gemgento/import.rb', line 24
def
@header_row
end
|
#row ⇒ Object
Returns the value of attribute row.
24
25
26
|
# File 'app/models/gemgento/import.rb', line 24
def row
@row
end
|
#spreadsheet ⇒ Object
Returns the value of attribute spreadsheet.
24
25
26
|
# File 'app/models/gemgento/import.rb', line 24
def spreadsheet
@spreadsheet
end
|
Instance Method Details
#content_index_range ⇒ Range
106
107
108
|
# File 'app/models/gemgento/import.rb', line 106
def content_index_range
((spreadsheet.first_row + 1)..spreadsheet.last_row)
end
|
#default_options ⇒ Object
47
48
49
|
# File 'app/models/gemgento/import.rb', line 47
def default_options
{}
end
|
#percentage_complete ⇒ Object
55
56
57
|
# File 'app/models/gemgento/import.rb', line 55
def percentage_complete
total_rows > 0 ? ((current_row.to_f / total_rows.to_f) * 100.0) : 0.0
end
|
#process ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'app/models/gemgento/import.rb', line 73
def process
Rails.logger.debug "Start #{self.class}.process"
Rails.logger.debug " header_row: #{self.}"
self.current_row = 0
self.processing!
while self.current_row < self.total_rows do
self.current_row += 1
self.row = spreadsheet.row(self.current_row + spreadsheet.first_row)
Rails.logger.debug " Working on Row #{self.current_row} - #{self.row}"
self.process_row
self.save!
end
self.complete!
Rails.logger.debug "Complete #{self.class}.process"
rescue Exception => e
self.process_errors << e.message
self.failed!
Rails.logger.error e
end
|
#process_later ⇒ Object
101
102
103
|
# File 'app/models/gemgento/import.rb', line 101
def process_later
Gemgento::ImportJob.perform_later(self)
end
|
#set_default_options ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/models/gemgento/import.rb', line 33
def set_default_options
self.options = default_options.merge(self.options || {})
self.options.keys.each do |key|
self.class.send :define_method, key do |*args|
self.options[key.to_sym]
end
self.class.send :define_method, "#{key}=" do |*args|
self.options[key.to_sym] = args.first
end
end
end
|
#set_default_process_errors ⇒ Object
29
30
31
|
# File 'app/models/gemgento/import.rb', line 29
def set_default_process_errors
self.process_errors ||= []
end
|
#set_total_rows ⇒ Object
51
52
53
|
# File 'app/models/gemgento/import.rb', line 51
def set_total_rows
self.total_rows = spreadsheet.last_row - spreadsheet.first_row
end
|
#value(code, type = :string) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/models/gemgento/import.rb', line 110
def value(code, type = :string)
index = .index(code)
value = row[index]
case type
when :boolean
return value.to_bool
when :string
return value.to_s.strip
else
return value
end
end
|