Sha256: b2cc86108a8a7cb413ab45e339ce4f9539ee1ec5d613f9890cbc926100e0c422

Contents?: true

Size: 1.26 KB

Versions: 38

Compression:

Stored size: 1.26 KB

Contents

module NetSuite
  module Records
    class ItemFulfillmentPackageList
      include Support::Fields
      include Support::Records
      include Namespaces::TranSales

      fields :package

      def initialize(attributes = {})
        if attributes.keys != [:package] && attributes.first

          transformed_attrs = {}
          object = attributes.first.last

          case object
          when Hash
            object.each do |k, v|
              transformed_attrs.merge!(k[0..-5].to_sym => v)
            end
          when Array
            object.each do |hash|
              hash.each do |k, v|
                transformed_attrs.merge!(k[0..-5].to_sym => v)
              end
            end
          end

          attributes = { package: transformed_attrs }
        end

        initialize_from_attributes_hash(attributes)
      end

      def package=(packages)
        case packages
        when Hash
          self.packages << ItemFulfillmentPackage.new(packages)
        when Array
          packages.each { |package| self.packages << ItemFulfillmentPackage.new(package) }
        end
      end

      def packages
        @packages ||= []
      end

      def to_record
        { "#{record_namespace}:package" => packages.map(&:to_record) }
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
netsuite-0.7.1 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.7.0 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.9 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.8 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.7 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.6 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.5 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.4 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.3 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.2 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.1 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.6.0 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.9 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.8 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.7 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.6 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.5 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.4 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.3 lib/netsuite/records/item_fulfillment_package_list.rb
netsuite-0.5.2 lib/netsuite/records/item_fulfillment_package_list.rb