Class: SteamCodec::ValueArray

Inherits:
Object
  • Object
show all
Defined in:
lib/steam_codec/value_array.rb

Direct Known Subclasses

ACF::CheckGuid, ACF::InstallScripts

Instance Method Summary collapse

Constructor Details

#initialize(valueHash = {}) ⇒ ValueArray



3
4
5
# File 'lib/steam_codec/value_array.rb', line 3

def initialize(valueHash = {})
    load(valueHash)
end

Instance Method Details

#[](id) ⇒ Object Also known as: get



15
16
17
# File 'lib/steam_codec/value_array.rb', line 15

def [](id)
    @ValueHash[id]
end

#[]=(id, file) ⇒ Object Also known as: set



19
20
21
# File 'lib/steam_codec/value_array.rb', line 19

def []=(id, file)
    @ValueHash[id] = file
end

#add(file) ⇒ Object



23
24
25
26
27
# File 'lib/steam_codec/value_array.rb', line 23

def add(file)
    id = @ValueHash.keys.max + 1
    @ValueHash[id] = file
    id
end

#load(valueHash) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/steam_codec/value_array.rb', line 7

def load(valueHash)
    raise ArgumentError, "ValueHash must be instance of Hash" unless valueHash.is_a?(Hash)
    @ValueHash = {}
    valueHash.each do |id, file|
        @ValueHash[id.to_i] = file
    end
end

#remove(id) ⇒ Object



29
30
31
# File 'lib/steam_codec/value_array.rb', line 29

def remove(id)
    @ValueHash.delete(id)
end

#to_aObject Also known as: all



33
34
35
36
37
38
39
# File 'lib/steam_codec/value_array.rb', line 33

def to_a
    check = []
    @ValueHash.sort_by { |key, value| key.to_s.to_i }.each do |array|
        check << array.last
    end
    check
end