Skip to content

Instantly share code, notes, and snippets.

@pewniak747
Last active August 29, 2015 14:04
Show Gist options
  • Save pewniak747/847830552e52256f74de to your computer and use it in GitHub Desktop.
Save pewniak747/847830552e52256f74de 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]) if time_data_present?
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
def time_data_present?
[params[:year], params[:month], params[:day]].all?(&: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