From 1f048db266b124367f6db199eb69ba2d9237c97e Mon Sep 17 00:00:00 2001 From: James Lavin Date: Fri, 21 Jun 2013 10:44:28 -0400 Subject: [PATCH] command_builders.rb refactoring --- lib/billing_logic/command_builders/command_builders.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/billing_logic/command_builders/command_builders.rb b/lib/billing_logic/command_builders/command_builders.rb index 801cc74..730976a 100644 --- a/lib/billing_logic/command_builders/command_builders.rb +++ b/lib/billing_logic/command_builders/command_builders.rb @@ -11,6 +11,8 @@ def self.money(money) end class ProductList + # ProductList.parse returns a dumb array + # You can't add behavior (I tried adding #price) def self.parse(string, options = {}) if (products = (string =~ /\(([^\(\)]*)\)/) ? $1 : nil) products.split(/ & /).map do |product_string| @@ -78,9 +80,8 @@ def add_action_string def add_bundle_action_string product_ids = products.map { |product| product.identifier }.join(' & ') price ||= products.inject(0){ |k, product| k += product.price; k } - price_string = BuilderHelpers.money(price) initial_payment_string = total_initial_payment.zero? ? '' : " with initial payment set to $#{BuilderHelpers.money(total_initial_payment)}" - "add (#{product_ids}) @ $#{price_string}#{periodicity_abbrev(products.first.billing_cycle.period)} on #{starts_on.strftime(STRFTIME)}#{initial_payment_string}" + "add (#{product_ids}) @ $#{BuilderHelpers.money(price)}#{periodicity_abbrev(products.first.billing_cycle.period)} on #{starts_on.strftime(STRFTIME)}#{initial_payment_string}" end def self.from_string(string, options = {:product_class => ProductStub}) @@ -92,7 +93,7 @@ def self.from_string(string, options = {:product_class => ProductStub}) $1.to_sym end opts[:disable] = !!(string =~ /and disable/) - opts[:starts_on] = (string =~ /on #{BillingLogic::CommandBuilders::DATE_REGEX}/) ? Date.strptime($1, '%m/%d/%y') : (string =~ /now$/) ? Time.now : nil + opts[:starts_on] = (string =~ /on #{BillingLogic::CommandBuilders::DATE_REGEX}/) ? Date.strptime($1, STRFTIME) : (string =~ /now$/) ? Time.now : nil opts[:products] = ProductList.parse(string, options) opts[:profile_id] = case opts[:action]