Class: CraftBook::NBT::StringTag

Inherits:
ValueTag show all
Defined in:
lib/craftbook/nbt/string_tag.rb

Overview

Represents a UTF-8 encoded string.

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 collapse

Attributes inherited from Tag

#name, #type

Instance Method Summary collapse

Methods inherited from ValueTag

#to_h

Methods inherited from Tag

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

Constructor Details

#initialize(name, value = '') ⇒ StringTag

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

Parameters:

  • name (String, NilClass)

    The name of the tag, or nil when unnamed.

  • value (String, NilClass) (defaults to: '')

    The value of the tag.



19
20
21
# File 'lib/craftbook/nbt/string_tag.rb', line 19

def initialize(name, value = '')
  super(TYPE_STRING, name, value)
end

Instance Attribute Details

#valueString

Returns the value of the tag.

Returns:

  • (String)

    the value of the tag.



# File 'lib/craftbook/nbt/string_tag.rb', line 10

Instance Method Details

#stringifyString

Returns the NBT tag as an SNBT string.

Returns:

  • (String)

    the NBT tag as an SNBT string.



35
36
37
# File 'lib/craftbook/nbt/string_tag.rb', line 35

def stringify
  "#{snbt_prefix}\"#{@value}\""
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.



29
30
31
# File 'lib/craftbook/nbt/string_tag.rb', line 29

def to_s
  "TAG_String(#{@name ? "\"#{@name}\"" : 'None'}): \"#{@value}\""
end