Skip to content

Instantly share code, notes, and snippets.

@wrzasa
Forked from pewniak747/form_object.rb
Last active August 29, 2015 14:07
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/9132b2f5159283be9ecf to your computer and use it in GitHub Desktop.
Save wrzasa/9132b2f5159283be9ecf 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(*[:year, :month, :day].map { |k| params[k] or raise ArgumentError})
rescue ArgumentError
end
def company_name
params[:_messed_up_company_name] || params[:company_name]
end
def valid?
billing_date.present? && company_name.present?
end
private
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