Skip to content

Instantly share code, notes, and snippets.

@wrzasa
Forked from pewniak747/form_object.rb
Created October 1, 2014 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrzasa/ed5bc8ab08dc15a57dd4 to your computer and use it in GitHub Desktop.
Save wrzasa/ed5bc8ab08dc15a57dd4 to your computer and use it in GitHub Desktop.
class InvoiceForm
attr_reader :params
def initialize(params)
@params = params
end
def billing_date
Time.new(params[:year], params[:month], params[:day])
rescue ArgumentError
end
def company_name
params[:_messed_up_company_name] || params[:company_name]
end
def valid?
billing_date.present? && company_name.present?
end
end
form = InvoiceForm.new({year: "2014", month: "07", day: "18"})
form.billing_date # => Time instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment