class RPM::TagData
- RPM::TagData
- Reference
- Object
Overview
Stores one RPM TagData.
There are multiple similar methods available for getting value(s).
#value
returns a value for non-array tag, an array for array tag, and a slice for binary tag.#value_no_array
returns a value for non-array tag and a slice for binary tags, but raises an exception for array tag.#value_array
returns an array for array tag and a slice for binary tags, but raises an exception for non-array tag.#to_a
returns an array for both non-array and array tags, and an array of single slice for binary tag.#[]
can be used for getting value at specific index for array tag, buttd[0]
is also available for non-array and binary tag.#value?
#value_no_array?
#value_array?
#[]?
returnsnil
instead of raising an exception.
Included Modules
- Indexable(Char | Slice(UInt8) | String | UInt16 | UInt32 | UInt64 | UInt8)
Defined in:
rpm/tagdata.crClass Method Summary
-
.create(deleter = nil, &)
Create a new tagdata with initializing it with given block.
-
.create(str : String, tag : Tag | TagValue)
Creates a new tagdata which stores given string.
-
.create(stra : Array(String), tag : Tag | TagValue)
Creates a new tagdata which stores given array of strings.
-
.create(u8 : UInt8, tag : Tag | TagValue)
Creates a new tagdata which stores given UInt8 value.
-
.create(u16 : UInt16, tag : Tag | TagValue)
Creates a new tagdata which stores given UInt16 value.
-
.create(u32 : UInt32, tag : Tag | TagValue)
Creates a new tagdata which stores given UInt32 value.
-
.create(u64 : UInt64, tag : Tag | TagValue)
Creates a new tagdata which stores given UInt64 value.
-
.create(u8a : Array(UInt8) | Bytes, tag : Tag | TagValue, copy : Bool = true)
Creates a new tagdata which stores given array of UInt8 values.
-
.create(u16a : Array(UInt16) | Slice(UInt16), tag : Tag | TagValue, copy : Bool = true)
Creates a new tagdata which stores given array of UInt16 values.
-
.create(u32a : Array(UInt32) | Slice(UInt32), tag : Tag | TagValue, copy : Bool = true)
Creates a new tagdata which stores given array of UInt32 values.
-
.create(u64a : Array(UInt64) | Slice(UInt64), tag : Tag | TagValue, copy : Bool = true)
Creates a new tagdata which stores given array of UInt64 values.
-
.create?(deleter = nil, &)
Create a new tagdata with initializing it with given block.
Instance Method Summary
-
#base64
Returns the BASE64 representation of tag data.
-
#bytes
Returns raw binary data of TagData
- #finalize
-
#force_return_type!(type : ReturnTypeBase.class)
Forces return type to given return type.
-
#format(fmt : TagDataFormat) : String
Format tag data in given tag data format, and returns it.
-
#format(io : IO, fmt : TagDataFormat) : Void
Format tag data in given tag data format, and send to given
io
-
#format(index : Int, fmt : TagDataFormat) : String
Format a single value at specified index of tag data in given tag data format, and return it.
-
#format(io : IO, index : Int, fmt : TagDataFormat) : Void
Format a single value at specified index of tag data in given tag data format, and return it.
-
#is_array?
Returns true if tag data is array
-
#return_type
Returns the return type of tag data
-
#size
Returns the number of elements in tag data
-
#tag
Get tag value
-
#tag=(val)
Sets tag value
-
#to_a
Returns an
Array
with all the elements in the collection. - #to_s(io)
-
#to_unsafe
Returns pointer to
rpmtd
to deal with librpm C API directly. -
#type
Returns the type of tag data
-
#unsafe_fetch(index : Int)
Returns the element at the given index, without doing any bounds check.
-
#value
Returns the value.
-
#value?
Returns the value.
-
#value_array
Returns the value in array.
-
#value_array?
Returns the value in array.
-
#value_no_array
Returns the single value of tag data
-
#value_no_array?
Returns the single value of tag data
Class Method Detail
Create a new tagdata with initializing it with given block.
This method is primitive method. Passed argument is raw value of
rpmtd
(actually a pointer).
If given block returns 0
, it will be treated as failure to set
tagdata, and raises TypeCastError
. You can raise another class
of Exception
in the block if you want to do so.
Creates a new tagdata which stores given string.
Creates a new tagdata which stores given array of strings.
Creates a new tagdata which stores given UInt8 value.
Creates a new tagdata which stores given UInt16 value.
Creates a new tagdata which stores given UInt32 value.
Creates a new tagdata which stores given UInt64 value.
Creates a new tagdata which stores given array of UInt8 values.
If copy
is false
, the content of u8a
will become a part of
TagData. Though u8a
will be kept until the TagData
is
garbage-collected, modifying it will also modifies the content
of TagData
.
Creates a new tagdata which stores given array of UInt16 values.
If copy
is false
, the content of u8a
will become a part of
TagData. Though u8a
will be kept until the TagData
is
garbage-collected, modifying it will also modifies the content
of TagData
.
Creates a new tagdata which stores given array of UInt32 values.
If copy
is false
, the content of u8a
will become a part of
TagData. Though u8a
will be kept until the TagData
is
garbage-collected, modifying it will also modifies the content
of TagData
.
Creates a new tagdata which stores given array of UInt64 values.
If copy
is false
, the content of u8a
will become a part of
TagData. Though u8a
will be kept until the TagData
is
garbage-collected, modifying it will also modifies the content
of TagData
.
Create a new tagdata with initializing it with given block.
This method is primitive method. Passed argument is raw value of
rpmtd
(actually a pointer).
If given block returns 0
, it will be treated as failure to set
tagdata, and returns nil
. You can NOT raise an exception in
the block, or make sure to rescue them.
Instance Method Detail
Returns the BASE64 representation of tag data.
Equivalent to #format(TagDataFormat::BASE64)
.
Returns raw binary data of TagData
Some types do not suitable for getting binary data. If so, this
method raises TypeCastError
.
Forces return type to given return type.
Returns old ReturnType class.
CHAR (ReturnTypeChar
), INT8 (ReturnTypeUInt8
) are
interoperable (except for #bytes
). Otherwise, it may cause
unexpected behavior.
Format tag data in given tag data format, and returns it.
Format tag data in given tag data format, and send to given io
Format a single value at specified index of tag data in given tag data format, and return it.
Format a single value at specified index of tag data in given tag data format, and return it.
Returns true if tag data is array
Returns true if number of elements is greater than 1, the return
type is TagReturnType::ARRAY
, or the type is
TagType::STRING_ARRAY
.
Sets tag value
NOTE RPM allows to change tag value only to same type. If not,
this method raises TypeCastError
.
Returns an Array
with all the elements in the collection.
{1, 2, 3}.to_a # => [1, 2, 3]
Returns the element at the given index, without doing any bounds check.
Indexable
makes sure to invoke this method with index in 0...size
,
so converting negative indices to positive ones is not needed here.
Clients never invoke this method directly. Instead, they access
elements with #[](index)
and #[]?(index)
.
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.
Returns the value in array.
It raises TypeCastError
if the tag data stores single value
only.
Returns the value in array.
It returns nil if the tag data stores single value only.
Returns the single value of tag data
If tag data contains array, raises TypeCastError
.
If tag data is not set, raises IndexError
(because this
methods just get the value at index 0).
Returns the single value of tag data
If tag data contains array or not set, returns nil.