Sha256: 90af1de156d5ecf51ad869b29ec367bd3858914afc09e1794ca367b6ab40a9a6

Contents?: true

Size: 613 Bytes

Versions: 1

Compression:

Stored size: 613 Bytes

Contents

# frozen_string_literal: true

module TJSON
  # TJSON object type (i.e. hash/dict-alike)
  class Object < ::Hash
    def []=(tagged_name, value)
      # NOTE: this regex is sloppy. The real parsing is performed in TJSON::DataType#parse
      result = tagged_name.match(/\A(?<name>.*):(?<tag>[A-Za-z0-9\<]+[\>]*)\z/)

      raise ParseError, "invalid tag: #{tagged_name.inspect}" unless result
      raise DuplicateNameError, "duplicate member name: #{result[:name].inspect}" if key?(result[:name])

      type = TJSON::DataType.parse(result[:tag])
      super(result[:name], type.decode(value))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tjson-0.5.0 lib/tjson/object.rb