Class: CraftBook::NBT::ContainerTag Abstract
- Inherits:
-
EnumerableTag
- Object
- Tag
- EnumerableTag
- CraftBook::NBT::ContainerTag
- Defined in:
- lib/craftbook/nbt/container_tag.rb
Overview
This class is abstract.
Abstract base class for tag types that can contain other Tag objects as children.
Direct Known Subclasses
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
Instance Method Summary collapse
-
#initialize(type, name, *values) ⇒ ContainerTag
constructor
Creates a new instance of the EnumerableTag class.
-
#pretty_print(io = STDOUT, level = 0, indent = ' ') ⇒ void
Outputs the NBT tag as a formatted and tree-structured string.
-
#to_h ⇒ Hash{Symbol => Object}
The hash-representation of this object.
Methods inherited from EnumerableTag
#[], #[]=, #each, #push, #size
Methods inherited from Tag
parse, #pretty, #stringify, #to_json
Constructor Details
#initialize(type, name, *values) ⇒ ContainerTag
Creates a new instance of the EnumerableTag class.
15 16 17 |
# File 'lib/craftbook/nbt/container_tag.rb', line 15 def initialize(type, name, *values) super(type, name, *values) end |
Instance Method Details
#pretty_print(io = STDOUT, level = 0, indent = ' ') ⇒ void
This method returns an undefined value.
Outputs the NBT tag as a formatted and tree-structured string.
34 35 36 37 38 39 40 |
# File 'lib/craftbook/nbt/container_tag.rb', line 34 def pretty_print(io = STDOUT, level = 0, indent = ' ') space = indent * level io.puts(space + to_s) io.puts(space + '{') each { |child| child.pretty_print(io, level + 1, indent) } io.puts(space + '}') end |
#to_h ⇒ Hash{Symbol => Object}
Returns the hash-representation of this object.
21 22 23 24 |
# File 'lib/craftbook/nbt/container_tag.rb', line 21 def to_h a = @values.map { |child| child.to_h } { name: @name, type: @type, values: a } end |