Class: Dhatu::Branch

Inherits:
ApplicationRecord show all
Includes:
Featureable, Publishable
Defined in:
app/models/dhatu/branch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.save_row_data(hsh) ⇒ Object



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)
  # Initializing error hash for displaying all errors altogether
  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.twitter = 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

Instance Method Details

#can_be_deleted?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'app/models/dhatu/branch.rb', line 132

def can_be_deleted?
  status?(:removed)
end

#can_be_edited?Boolean

Permission Methods


Returns:

  • (Boolean)


128
129
130
# File 'app/models/dhatu/branch.rb', line 128

def can_be_edited?
  status?(:published) or status?(:unpublished)
end

#display_addressObject



121
122
123
# File 'app/models/dhatu/branch.rb', line 121

def display_address
  [self.address_1, self.address_2, self.address_3].compact.uniq.join(", ")
end

#display_nameObject



117
118
119
# File 'app/models/dhatu/branch.rb', line 117

def display_name
  "#{title_was}"
end

#to_paramObject

Generic Methods




113
114
115
# File 'app/models/dhatu/branch.rb', line 113

def to_param
  "#{id}-#{title.parameterize[0..32]}"
end