Skip to content
This repository
Browse code

Refactor to fewer 'if' statements.

  • Loading branch information...
commit 2dde9ed72e39cfe6bb31fe40f730b285003642d4 1 parent e775167
Gabe Berke-Williams authored January 13, 2012

Showing 1 changed file with 11 additions and 13 deletions. Show diff stats Hide diff stats

  1. 24  lib/fake_braintree/customer.rb
24  lib/fake_braintree/customer.rb
@@ -42,22 +42,20 @@ def customer_hash
42 42
       hash = @customer_hash.dup
43 43
       hash["id"] ||= create_id
44 44
 
45  
-      if hash["credit_card"] && hash["credit_card"].is_a?(Hash)
46  
-        if !hash["credit_card"].empty?
47  
-          hash["credit_card"]["last_4"] = last_four(hash)
48  
-          hash["credit_card"]["token"]  = credit_card_token(hash)
  45
+      if hash["credit_card"].present? && hash["credit_card"].is_a?(Hash)
  46
+        hash["credit_card"]["last_4"] = last_four(hash)
  47
+        hash["credit_card"]["token"]  = credit_card_token(hash)
49 48
 
50  
-          if credit_card_expiration_month
51  
-            hash["credit_card"]["expiration_month"] = credit_card_expiration_month
52  
-          end
53  
-
54  
-          if credit_card_expiration_year
55  
-            hash["credit_card"]["expiration_year"] = credit_card_expiration_year
56  
-          end
  49
+        if credit_card_expiration_month
  50
+          hash["credit_card"]["expiration_month"] = credit_card_expiration_month
  51
+        end
57 52
 
58  
-          credit_card = hash.delete("credit_card")
59  
-          hash["credit_cards"] = [credit_card]
  53
+        if credit_card_expiration_year
  54
+          hash["credit_card"]["expiration_year"] = credit_card_expiration_year
60 55
         end
  56
+
  57
+        credit_card = hash.delete("credit_card")
  58
+        hash["credit_cards"] = [credit_card]
61 59
       else
62 60
         hash["credit_cards"] = []
63 61
       end

0 notes on commit 2dde9ed

Please sign in to comment.
Something went wrong with that request. Please try again.