Class: Exerb::Resource::VersionInfo::BlockBase

Inherits:
Object
  • Object
show all
Defined in:
lib/exerb/resource/version_info.rb

Direct Known Subclasses

BlockType0, BlockType1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, key, value = '', unicode = false) {|_self| ... } ⇒ BlockBase

Returns a new instance of BlockBase

Yields:

  • (_self)

Yield Parameters:


97
98
99
100
101
102
103
104
105
# File 'lib/exerb/resource/version_info.rb', line 97

def initialize(type, key, value = '', unicode = false)
  @type     = type
  @key      = key
  @value    = value
  @unicode  = unicode
  @children = []

  yield(self) if block_given?
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children


107
108
109
# File 'lib/exerb/resource/version_info.rb', line 107

def children
  @children
end

#keyObject

Returns the value of attribute key


107
108
109
# File 'lib/exerb/resource/version_info.rb', line 107

def key
  @key
end

#typeObject

Returns the value of attribute type


107
108
109
# File 'lib/exerb/resource/version_info.rb', line 107

def type
  @type
end

#unicodeObject

Returns the value of attribute unicode


107
108
109
# File 'lib/exerb/resource/version_info.rb', line 107

def unicode
  @unicode
end

#valueObject

Returns the value of attribute value


107
108
109
# File 'lib/exerb/resource/version_info.rb', line 107

def value
  @value
end

Instance Method Details

#<<(child) ⇒ Object


109
110
111
# File 'lib/exerb/resource/version_info.rb', line 109

def <<(child)
  @children << child
end

#packObject


113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/exerb/resource/version_info.rb', line 113

def pack
  packed_children = @children.collect { |child| child.pack }.join

  block = Exerb::Win32::Struct::VersionInfoBlock.new
  block.type         = @type
  block.key          = @key.unpack("U*").pack("v*") # UTF-8 to UTF-16LE
  block.data         = @value
  block.value_length = (@unicode ? @value.size / 2 : @value.size)
  block.total_length = block.pack.size + packed_children.size

  return Exerb::Utility.alignment(block.pack, 4) + packed_children
end