60
61
62
63
64
65
66
67
68
69
70
71
72
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
100
101
102
103
104
105
|
# File 'app/models/dhatu/branch.rb', line 60
def self.save_row_data(hsh)
error_object = Kuppayam::Importer::ErrorHash.new
return error_object if hsh[:title].to_s.strip.blank?
branch = Dhatu::Branch.find_by_title(hsh[:title].to_s.strip) || Dhatu::Branch.new
branch.title = hsh[:title].to_s.strip
branch.address_1 = hsh[:address_1].to_s.strip
branch.address_2 = hsh[:address_2].to_s.strip
branch.address_3 = hsh[:address_3].to_s.strip
branch.email = hsh[:email].to_s.strip
branch.landline = hsh[:landline].to_s.strip
branch.fax = hsh[:fax].to_s.strip
branch.mobile = hsh[:mobile].to_s.strip
branch.facebook = hsh[:facebook].to_s.strip
branch. = hsh[:twitter].to_s.strip
branch.google_plus = hsh[:google_plus].to_s.strip
branch.linked_in = hsh[:linked_in].to_s.strip
branch.youtube = hsh[:youtube].to_s.strip
branch.instagram = hsh[:instagram].to_s.strip
branch.tumblr = hsh[:tumblr].to_s.strip
branch.pinterest = hsh[:pinterest].to_s.strip
branch.blog = hsh[:blog].to_s.strip
branch.status = hsh[:status].to_s.strip.blank? ? PUBLISHED : hsh[:status].to_s.strip
branch.featured = ["true", "t","1","yes","y"].include?(hsh[:featured].to_s.downcase.strip)
branch.main_branch = ["true", "t","1","yes","y"].include?(hsh[:main_branch].to_s.downcase.strip)
if branch.valid?
begin
branch.save!
rescue Exception => e
summary = "uncaught #{e} exception while handling connection: #{e.message}"
details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}"
error_object.errors << { summary: summary, details: details }
end
else
summary = "Error while saving branch: #{branch.title}"
details = "Error! #{branch.errors.full_messages.to_sentence}"
error_object.errors << { summary: summary, details: details }
end
return error_object
end
|