Class: Organization

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper
Defined in:
app/models/organization.rb

Constant Summary collapse

ORGANIZATION_FORM_OPTIONS =

include PublicActivity::Model tracked owner: -> controller, model { controller.current_user },

recipient: -> controller, model { controller.current_user.organization }, 
params: {
  author_name: -> controller, model { controller.current_user.username },
  author_email: -> controller, model { controller.current_user.email },
  object_name: -> controller, model { model.name },
  summary: -> controller, model { model.changes }
}
{
  storage: :s3,
  s3_protocol: 'https',
  s3_credentials: {access_key_id: ENV['S3_KEY'], secret_access_key: ENV['S3_SECRET']},
  bucket: 'hospitium-static-v2',
  url: '/system/:attachment/:hash/:filename',
  hash_secret: ENV['SALTY']
}

Instance Method Summary collapse

Instance Method Details

#add_default_animal_colorsObject

create the default animal colors and assign them to the new organization


70
71
72
73
74
75
76
# File 'app/models/organization.rb', line 70

def add_default_animal_colors
  ['Black', 'White', 'Gray', 'Brown'].each do |color_name|
    animal_color = AnimalColor.new(color: color_name)
    animal_color.organization_id = self.id
    animal_color.save
  end
end

#add_default_speciesObject

create the default species and assign them to the new organization


79
80
81
82
83
84
85
# File 'app/models/organization.rb', line 79

def add_default_species
  ['Cat', 'Dog', 'Hamster', 'Gerbil', 'Chinchilla', 'Bird', 'Rat', 'Mouse'].each do |species_name|
    species = Species.new(name: species_name)
    species.organization_id = self.id
    species.save
  end
end

#add_default_statusObject

create the default statuses and assign them to the new organization


61
62
63
64
65
66
67
# File 'app/models/organization.rb', line 61

def add_default_status
  ['Adoptable', 'New Intake', 'Sanctuary', 'Sick', 'Deceased', 'Adopted', 'Foster Care'].each do |status_name|
    status = Status.new(status: status_name)
    status.organization_id = self.id
    status.save
  end
end

#formatted_phoneObject


93
94
95
# File 'app/models/organization.rb', line 93

def formatted_phone
  self.phone_number.blank? ? '' : number_to_phone(self.phone_number)
end

#full_addressObject


102
103
104
# File 'app/models/organization.rb', line 102

def full_address
  "#{address} #{city} #{state} #{zip_code}"
end

#has_info?Boolean

Returns:

  • (Boolean)

97
98
99
100
# File 'app/models/organization.rb', line 97

def has_info?
  return false if self.phone_number.blank? and self.email.blank? and self.website.blank?
  true
end

#modify_phone_numberObject


87
88
89
90
91
# File 'app/models/organization.rb', line 87

def modify_phone_number
  # unless self.phone_number.blank?
    self.phone_number = self.phone_number.delete("^0-9") unless self.phone_number.blank?
  # end
end

#ownerObject


106
107
108
# File 'app/models/organization.rb', line 106

def owner
  User.where(organization_id: self.id, owner: 1).first
end

#pretty_websiteObject


110
111
112
113
114
115
116
# File 'app/models/organization.rb', line 110

def pretty_website
  if self.website && !url_protocol_present?
    "http://#{self.website}"
  else
    self.website
  end
end