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

Returns a new instance of ValueArray.



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

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

Instance Method Details

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



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

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

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



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

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

#add(file) ⇒ Object



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

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

#load(valueHash) ⇒ Object

Raises:

  • (ArgumentError)


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

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



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

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

#to_aObject Also known as: all



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

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

#to_hashObject



46
47
48
# File 'lib/steam_codec/value_array.rb', line 46

def to_hash
    @ValueHash
end