Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CoworkingSpace < ActiveRecord::Base
- has_many :tables
- has_many :products
- belongs_to :user
- belongs_to :city
- belongs_to :category
- has_many :image_coworking_spaces
- has_many :images, :through => :image_coworking_spaces
- has_many :item_categories, dependent: :destroy
- mount_uploader :map_file, ImageUploader
- attr_accessor :category_name
- attr_accessible :start_time_download_coupons, :end_time_download_coupons, :name,
- :description, :city_id, :lat, :long, :address, :user_id, :category_id, :url, :map_file, :map_text_url, :remove_map_file
- scope :promotions, scoped
- scope :hot_promotions, promotions.limit(3)
- def map_url
- return self.map_file_url if self.map_file?
- return self.map_text_url if self.map_text_url?
- end
- def create_tables
- end
- def price
- if percentage_booked <= 0.3
- green
- elsif percentage_booked <= 0.6
- yellow
- else
- red
- end
- end
- def tables_left(type)
- (tables.where('tipo = ?', type).count) - (tables.where('booked = ? and tipo = ? ', true, type).count)
- end
- def percentage_booked
- tables_booked / tables.where(:tipo => 'resource').count.to_f
- end
- def tables_booked
- tables.where('tipo = ? ', 'resource').select(&:booked).count
- end
- def prices
- @prices ||= []
- item_categories.each do |category|
- @prices << category.price(self)
- end
- @prices
- end
- def products_quantity
- return 0 if item_categories.empty?
- item_categories.sum(:num_tables)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement