Permalink
Browse files

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

…arquivo items.rb.
  • Loading branch information...
1 parent f708bc5 commit 827a1c0ff61b65823a7b236f6509e2dabfb13d01 Bruno Azisaka Maciel committed Oct 21, 2008
Showing with 30 additions and 0 deletions.
  1. +30 −0 pagseguro/lib/items.rb
View
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/item'
+
+class Items < Array
+ def <<(item)
+ raise InvalidItem unless item.class.eql? Item
+ self.push(item)
+ end
+
+ def total
+ self.map { |i| i.total }.inject { |sum, n| sum + n }
+ end
+
+ def weight
+ self.map { |i| i.weight }.inject { |sum, n| sum + n }
+ end
+
+ def to_params
+ params = []
+
+ self.each_with_index do |item, i|
+ params << "item_id_#{i+1}=#{item.id}"
+ params << "item_descr_#{i+1}=#{URI.escape(item.descr)}"
+ params << "item_quant_#{i+1}=#{item.quant}"
+ params << "item_valor_#{i+1}=#{item.valor}"
+ params << "item_peso_#{i+1}=#{item.weight}"
+ end
+
+ params
+ end
+end

0 comments on commit 827a1c0

Please sign in to comment.