-
-
Save wrzasa/9132b2f5159283be9ecf to your computer and use it in GitHub Desktop.
This file contains hidden or 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(*[: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