Sha256: 02364a1dbaf06340608db2dcd5d39d0d3a0c2eb2ad6d9655bd23c8c1c9986e99

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RASN1
  module Types
    # @abstract This class SHOULD be used as base class for all ASN.1 primitive
    #  types.
    # Base class for all ASN.1 constructed types
    # @author Sylvain Daubert
    class Constructed < Base
      # Constructed value
      ASN1_PC = 0x20

      # @return [Boolean]
      # @since 0.12.0
      # @see Base#can_build?
      def can_build? # rubocop:disable Metrics/CyclomaticComplexity
        return super unless @value.is_a?(Array) && optional?
        return false unless super

        @value.any? do |el|
          el.can_build? && (
            el.primitive? ||
              (el.value.respond_to?(:empty?) ? !el.value.empty? : !el.value.nil?))
        end
      end

      # @param [::Integer] level (default: 0)
      # @return [String]
      def inspect(level=0)
        case @value
        when Array
          str = common_inspect(level)
          str << "\n"
          level = level.abs + 1
          @value.each do |item|
            case item
            when Base, Model, Wrapper
              str << "#{item.inspect(level)}\n"
            else
              str << '  ' * level
              str << "#{item.inspect}\n"
            end
          end
          str
        else
          super
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rasn1-0.13.1 lib/rasn1/types/constructed.rb
rasn1-0.13.0 lib/rasn1/types/constructed.rb
rasn1-0.12.1 lib/rasn1/types/constructed.rb
rasn1-0.12.0 lib/rasn1/types/constructed.rb