Last active
August 29, 2015 14:04
-
-
Save pewniak747/847830552e52256f74de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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