Sha256: 2dba6ccb2271fce86c6f58b8bf4c21670fa6d6424c79e2f7efb72f86842290ec

Contents?: true

Size: 679 Bytes

Versions: 5

Compression:

Stored size: 679 Bytes

Contents

module ShipCompliant
  # == ShipCompliant::ShipmentCompliance
  #
  # Wrap the +ShipmentComplianceResponse+ node.
  class ShipmentCompliance < Struct.new(:result)

    # Checks if the shipment was compliant.
    def compliant?
      result[:is_compliant]
    end

    # Returns the shipment key.
    def shipment_key
      result[:key]
    end

    # Wraps the +RuleComplianceResponse+ nodes with ComplianceRule.
    #
    #   compliance_errors = shipment.rules.reject { |r| r.compliant? }
    def rules
      return [] if result[:rules].nil?
      Array.wrap(result[:rules][:rule_compliance_response]).map do |rule|
        ComplianceRule.new(rule)
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ship_compliant-0.2.1 lib/ship_compliant/shipment_compliance.rb
ship_compliant-0.2.0 lib/ship_compliant/shipment_compliance.rb
ship_compliant-0.1.2 lib/ship_compliant/shipment_compliance.rb
ship_compliant-0.1.1 lib/ship_compliant/shipment_compliance.rb
ship_compliant-0.1.0 lib/ship_compliant/shipment_compliance.rb