Skip to content
This repository
Browse code

Fazendo merge das modificações do darkseid e adicionando novamente o …

…arquivo items.rb.
  • Loading branch information...
commit 827a1c0ff61b65823a7b236f6509e2dabfb13d01 1 parent f708bc5
authored October 21, 2008

Showing 1 changed file with 30 additions and 0 deletions. Show diff stats Hide diff stats

  1. 30  pagseguro/lib/items.rb
30  pagseguro/lib/items.rb
... ...
@@ -0,0 +1,30 @@
  1
+require File.dirname(__FILE__) + '/item'
  2
+
  3
+class Items < Array
  4
+  def <<(item)
  5
+    raise InvalidItem unless item.class.eql? Item
  6
+    self.push(item)
  7
+  end
  8
+  
  9
+  def total
  10
+    self.map { |i| i.total }.inject { |sum, n| sum + n }
  11
+  end
  12
+  
  13
+  def weight
  14
+    self.map { |i| i.weight }.inject { |sum, n| sum + n }
  15
+  end
  16
+  
  17
+  def to_params
  18
+    params = []
  19
+    
  20
+    self.each_with_index do |item, i|
  21
+      params << "item_id_#{i+1}=#{item.id}"
  22
+      params << "item_descr_#{i+1}=#{URI.escape(item.descr)}"
  23
+      params << "item_quant_#{i+1}=#{item.quant}"
  24
+      params << "item_valor_#{i+1}=#{item.valor}"
  25
+      params << "item_peso_#{i+1}=#{item.weight}"
  26
+    end
  27
+    
  28
+    params
  29
+  end
  30
+end

0 notes on commit 827a1c0

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