Class: PurchaseRequest

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/purchase_request.rb

Instance Method Summary collapse

Instance Method Details

#check_priceObject



44
45
46
# File 'app/models/purchase_request.rb', line 44

def check_price
  errors.add(:price) unless self.price.nil? || self.price > 0
end

#set_date_of_publicationObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/purchase_request.rb', line 48

def set_date_of_publication
  return if pub_date.blank?
  begin
    date = Time.zone.parse("#{pub_date}")
  rescue ArgumentError
    begin
      date = Time.zone.parse("#{pub_date}-01")
    rescue ArgumentError
      begin
        date = Time.zone.parse("#{pub_date}-01-01")
      rescue ArgumentError
        nil
      end
    end
  end
  self.date_of_publication = date
end