Sha256: 3dc9b20e5f80db378fe07bb0a38f0f45c4b1f677bff81bc0d797fec767209fe8

Contents?: true

Size: 667 Bytes

Versions: 9

Compression:

Stored size: 667 Bytes

Contents

module Lutaml
  module Model
    class MappingHash < Hash
      attr_accessor :ordered

      def initialize
        @ordered = false
        @item_order = []

        super
      end

      def item_order
        @item_order&.map { |key| normalize(key) } || keys
      end

      def item_order=(order)
        raise "`item order` must be an array" unless order.is_a?(Array)

        @item_order = order
      end

      def ordered?
        @ordered
      end

      private

      def normalize(key)
        if self[key.to_s]
          key.to_s
        elsif self[key.to_sym]
          key.to_sym
        else
          key
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lutaml-model-0.3.10 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.9 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.8 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.7 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.6 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.5 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.4 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.3 lib/lutaml/model/mapping_hash.rb
lutaml-model-0.3.2 lib/lutaml/model/mapping_hash.rb