Class: SteamCodec::ACF::UserConfig

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(userConfig = nil) ⇒ UserConfig

Returns a new instance of UserConfig.



123
124
125
# File 'lib/steam_codec/acf.rb', line 123

def initialize(userConfig = nil)
    load(userConfig || KeyValues.new)
end

Instance Attribute Details

#AppInstallDirObject

Returns the value of attribute AppInstallDir.



116
117
118
# File 'lib/steam_codec/acf.rb', line 116

def AppInstallDir
  @AppInstallDir
end

#BetaKeyObject

Returns the value of attribute BetaKey.



118
119
120
# File 'lib/steam_codec/acf.rb', line 118

def BetaKey
  @BetaKey
end

#GameIDObject

Returns the value of attribute GameID.



114
115
116
# File 'lib/steam_codec/acf.rb', line 114

def GameID
  @GameID
end

#InstalledObject

Returns the value of attribute Installed.



115
116
117
# File 'lib/steam_codec/acf.rb', line 115

def Installed
  @Installed
end

#LanguageObject

Returns the value of attribute Language.



117
118
119
# File 'lib/steam_codec/acf.rb', line 117

def Language
  @Language
end

#NameObject

Returns the value of attribute Name.



113
114
115
# File 'lib/steam_codec/acf.rb', line 113

def Name
  @Name
end

Class Method Details

.scalarFieldsObject



119
120
121
# File 'lib/steam_codec/acf.rb', line 119

def self.scalarFields
    return [:Name, :GameID, :Installed, :AppInstallDir, :Language, :BetaKey]
end

Instance Method Details

#get(path = '', seperator = '.') ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/steam_codec/acf.rb', line 138

def get(path = '', seperator = '.')
    return nil unless @UserConfig
    fields = path.split(seperator)
    return to_hash unless fields.first
    self.class.scalarFields.each do |field|
        if field.to_s.downcase == fields.first.downcase
            return self.send(field)
        end
    end
    @UserConfig.get(path, seperator)
end

#load(userConfig) ⇒ Object

Raises:

  • (ArgumentError)


127
128
129
130
131
132
133
134
135
136
# File 'lib/steam_codec/acf.rb', line 127

def load(userConfig)
    raise ArgumentError, "UserConfig must be instance of KeyValues" unless userConfig.is_a?(KeyValues)
    @UserConfig = userConfig
    @Name = @UserConfig.name if @UserConfig.key?(:name)
    @GameID = @UserConfig.gameid.to_i if @UserConfig.key?(:gameid)
    @Installed = !@UserConfig.installed.to_i.zero? if @UserConfig.key?(:installed)
    @AppInstallDir = @UserConfig.appinstalldir if @UserConfig.key?(:appinstalldir)
    @Language = @UserConfig.language if @UserConfig.key?(:language)
    @BetaKey = @UserConfig.BetaKey if @UserConfig.key?(:BetaKey)
end

#to_hashObject



150
151
152
153
154
155
156
# File 'lib/steam_codec/acf.rb', line 150

def to_hash
    result = {}
    self.class.scalarFields.each do |field|
        result[field.to_s] = self.send(field)
    end
    result
end