Class: Ms::BinaryResources::Reader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ms/binary/resources/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Reader

Returns a new instance of Reader.



13
14
15
16
17
18
# File 'lib/ms/binary/resources/reader.rb', line 13

def initialize(uri)
  @file = open(uri, 'rb')
  read_headers
rescue => e
  fail ArgumentError, "file does not appear to be a resources file (#{e})"
end

Instance Attribute Details

#manager_lengthObject (readonly)

Returns the value of attribute manager_length.



11
12
13
# File 'lib/ms/binary/resources/reader.rb', line 11

def manager_length
  @manager_length
end

#manager_magicObject (readonly)

Returns the value of attribute manager_magic.



11
12
13
# File 'lib/ms/binary/resources/reader.rb', line 11

def manager_magic
  @manager_magic
end

#manager_versionObject (readonly)

Returns the value of attribute manager_version.



11
12
13
# File 'lib/ms/binary/resources/reader.rb', line 11

def manager_version
  @manager_version
end

#resource_countObject (readonly)

Returns the value of attribute resource_count.



11
12
13
# File 'lib/ms/binary/resources/reader.rb', line 11

def resource_count
  @resource_count
end

#resource_versionObject (readonly)

Returns the value of attribute resource_version.



11
12
13
# File 'lib/ms/binary/resources/reader.rb', line 11

def resource_version
  @resource_version
end

#type_countObject (readonly)

Returns the value of attribute type_count.



11
12
13
# File 'lib/ms/binary/resources/reader.rb', line 11

def type_count
  @type_count
end

Instance Method Details

#[](name) ⇒ Object



40
41
42
43
# File 'lib/ms/binary/resources/reader.rb', line 40

def [](name)
  info = info_for_name(name)
  info ? read_value(info) : nil
end

#closeObject



45
46
47
48
# File 'lib/ms/binary/resources/reader.rb', line 45

def close
  @file.close
  @file = nil
end

#each(&block) ⇒ Object



20
21
22
# File 'lib/ms/binary/resources/reader.rb', line 20

def each(&block)
  keys.each { |k| block.call(k, (self[k] rescue nil)) }
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ms/binary/resources/reader.rb', line 24

def key?(name)
  info_for_name(name)
end

#keysObject



28
29
30
# File 'lib/ms/binary/resources/reader.rb', line 28

def keys
  @keys ||= @resource_infos.map(&:name)
end

#type_of(name) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ms/binary/resources/reader.rb', line 32

def type_of(name)
  info = info_for_name(name)
  if info
    type = RESOURCE_TYPES.find { |_, v| info.type_index == v }
    type && type.first
  end
end