Sha256: aa5e918bcfad2b513fb582231ffa7d3c9b11d77d2c86833b000315b3552d269f

Contents?: true

Size: 974 Bytes

Versions: 4

Compression:

Stored size: 974 Bytes

Contents

module Xsys
  module Model
    class ProductPriceList
      def self.attr_list
        [:product_id, :product_name, :price_list_id, :taxed_price, :total_price,
         :markup, :price_update_date, :price_update_time]
      end

      attr_reader *attr_list

      def initialize(attributes={})
        time_fields = ['price_update_time']
        date_fields = ['price_update_date']
        decimal_fields = ['total_price', 'taxed_price', 'markup']

        attributes.each do |k, v|
          if time_fields.include?(k.to_s)
            self.send("#{k}=", Time.parse(v)) unless v.nil?
          elsif date_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

4 entries across 4 versions & 1 rubygems

Version Path
xsys-0.19.2 lib/xsys/model/product_price_list.rb
xsys-0.19.1 lib/xsys/model/product_price_list.rb
xsys-0.19.0 lib/xsys/model/product_price_list.rb
xsys-0.18 lib/xsys/model/product_price_list.rb