Sha256: 4b9c1c76d0abb2c491335addf0c3d48e8374baea611e8273f9ea70f08efcd1f4

Contents?: true

Size: 1001 Bytes

Versions: 71

Compression:

Stored size: 1001 Bytes

Contents

module Xsys
  module Model
    class Sale
      def self.attr_list
        [:code, :transaction_number, :shop_code, :transaction_kind_code, :transaction_status_id,
        :customer_code, :receipt_number, :receipt_date, :total_amount, :seller_code, :observations,
        :user_login, :sale_order_code, :receiver_name, :cuit, :items]
      end

      attr_reader *attr_list

      def initialize(attributes={})
        time_fields = ['receipt_date']
        decimal_fields = ['total_amount']

        attributes.each do |k, v|
          if k.to_s == 'items'
            self.items = v.map { |s| SaleItem.new(s) }
          elsif time_fields.include?(k.to_s)
            self.send("#{k}=", Date.parse(v)) unless v.nil?
          elsif decimal_fields.include?(k.to_s)
            self.send("#{k}=", BigDecimal.new(v)) unless v.nil?
          else
            self.send("#{k}=", v) if self.respond_to?(k)
          end
        end
      end

      private

      attr_writer *attr_list
    end
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
xsys-0.8.0 lib/xsys/model/sale.rb
xsys-0.7.0 lib/xsys/model/sale.rb
xsys-0.6.5 lib/xsys/model/sale.rb
xsys-0.6.4 lib/xsys/model/sale.rb
xsys-0.6.3 lib/xsys/model/sale.rb
xsys-0.6.2 lib/xsys/model/sale.rb
xsys-0.6.1 lib/xsys/model/sale.rb
xsys-0.6.0 lib/xsys/model/sale.rb
xsys-0.5.2 lib/xsys/model/sale.rb
xsys-0.5.1 lib/xsys/model/sale.rb
xsys-0.5.0 lib/xsys/model/sale.rb