Class: DMAPParser::Tag

Inherits:
Struct
  • Object
show all
Defined in:
lib/dmapparser/tag.rb

Overview

The Tag class

Direct Known Subclasses

TagContainer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value) ⇒ Tag

Returns a new instance of Tag.



4
5
6
7
8
9
10
# File 'lib/dmapparser/tag.rb', line 4

def initialize(type, value)
  unless type.is_a? TagDefinition
    type = TagDefinition[type] ||
           TagDefinition.new(type, :unknown, "unknown (#{length})")
  end
  super
end

Instance Attribute Details

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/dmapparser/tag.rb', line 3

def type
  @type
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



3
4
5
# File 'lib/dmapparser/tag.rb', line 3

def value
  @value
end

Instance Method Details

#inspect(level = 0) ⇒ Object



16
17
18
# File 'lib/dmapparser/tag.rb', line 16

def inspect(level = 0)
  "#{'  ' * level}#{type}: #{value}"
end

#to_dmapObject



20
21
22
23
24
# File 'lib/dmapparser/tag.rb', line 20

def to_dmap
  value = convert_value(self.value)
  length = [value.length].pack('N')
  (type.tag.to_s + length + value).force_encoding(Encoding::BINARY)
end

#to_sObject



12
13
14
# File 'lib/dmapparser/tag.rb', line 12

def to_s
  "#<#{self.class.name} #{type}>"
end