Class: Ms::BinaryResources::Reader
- Inherits:
-
Object
- Object
- Ms::BinaryResources::Reader
- Includes:
- Enumerable
- Defined in:
- lib/ms/binary/resources/reader.rb
Instance Attribute Summary collapse
-
#manager_length ⇒ Object
readonly
Returns the value of attribute manager_length.
-
#manager_magic ⇒ Object
readonly
Returns the value of attribute manager_magic.
-
#manager_version ⇒ Object
readonly
Returns the value of attribute manager_version.
-
#resource_count ⇒ Object
readonly
Returns the value of attribute resource_count.
-
#resource_version ⇒ Object
readonly
Returns the value of attribute resource_version.
-
#type_count ⇒ Object
readonly
Returns the value of attribute type_count.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #close ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(uri) ⇒ Reader
constructor
A new instance of Reader.
- #key?(name) ⇒ Boolean
- #keys ⇒ Object
- #type_of(name) ⇒ Object
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_length ⇒ Object (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_magic ⇒ Object (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_version ⇒ Object (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_count ⇒ Object (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_version ⇒ Object (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_count ⇒ Object (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 |
#close ⇒ Object
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
24 25 26 |
# File 'lib/ms/binary/resources/reader.rb', line 24 def key?(name) info_for_name(name) end |
#keys ⇒ Object
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 |