Class: CraftBook::NBT::CompoundTag

Inherits:
ContainerTag show all
Defined in:
lib/craftbook/nbt/compound_tag.rb

Overview

Represents a collection of named tags, order not guaranteed.

Constant Summary

Constants inherited from Tag

Tag::TYPE_BYTE, Tag::TYPE_BYTE_ARRAY, Tag::TYPE_COMPOUND, Tag::TYPE_DOUBLE, Tag::TYPE_END, Tag::TYPE_FLOAT, Tag::TYPE_INT, Tag::TYPE_INT_ARRAY, Tag::TYPE_LIST, Tag::TYPE_LONG, Tag::TYPE_LONG_ARRAY, Tag::TYPE_SHORT, Tag::TYPE_STRING

Instance Attribute Summary

Attributes inherited from Tag

#name, #type

Instance Method Summary collapse

Methods inherited from ContainerTag

#pretty_print, #to_h

Methods inherited from EnumerableTag

#[], #[]=, #each, #push, #size, #to_h

Methods inherited from Tag

parse, #pretty, #pretty_print, #to_h, #to_json

Constructor Details

#initialize(name, *values) ⇒ CompoundTag

Creates a new instance of the CraftBook::NBT::CompoundTag class.

Parameters:

  • name (String, NilClass)

    The name of the tag, or nil when unnamed.

  • values (Array<Tag>)

    Zero or more values to add during initialization.



15
16
17
# File 'lib/craftbook/nbt/compound_tag.rb', line 15

def initialize(name, *values)
  super(TYPE_COMPOUND, name, *values)
end

Instance Method Details

#stringifyString

Returns the NBT tag as an SNBT string.

Returns:

  • (String)

    the NBT tag as an SNBT string.



27
28
29
# File 'lib/craftbook/nbt/compound_tag.rb', line 27

def stringify
  "{#{snbt_prefix}{#{map(&:stringify).join(',')}}"
end

#to_sString

Returns the NBT tag as a formatted and human-readable string.

Returns:

  • (String)

    the NBT tag as a formatted and human-readable string.



21
22
23
# File 'lib/craftbook/nbt/compound_tag.rb', line 21

def to_s
  "TAG_Compound(#{@name ? "\"#{@name}\"" : 'None'}): #{size} #{size == 1 ? 'child' : 'children'}"
end