steam_codec 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93fd1b633432abfc06e6bb11aec0df481b4e366e
4
- data.tar.gz: 89a9ca4cb5975b3abcbf0c6e818f61cf333bdbfe
3
+ metadata.gz: 12716a694221e90c59aef584f78564a9e487e844
4
+ data.tar.gz: 5ee52a82e9625c6c27287868bcd168407f9ae0da
5
5
  SHA512:
6
- metadata.gz: b28226526d56a91911f058ed1be3a397825851cf41cef6700f212891dd2fa033896d6c8a52eeb84d910dcfff83a62995e345317528ca7b7e5edfb4e295c5cbb3
7
- data.tar.gz: fb81d45dc2484c102e704024fad68014aed5115ada853d8fb9da4c632657c9e82431e0ff87db9c3d59bb615e2c3a2c9d4347fbf10623e25dff5992851d1230ce
6
+ metadata.gz: a553ef7279396429e7b42102fa189695ee2f217205fb12d476e1c25c166fe8123fa77410b91a5ec7bfda7895d077acc2fb7a6cafaff6d3415f59c7b9d670acda
7
+ data.tar.gz: af332c56e96acec50ee65eb53780b9730e76ad96f550fec5e5c5152e77be2d364d3f7837ada0614c202272b13ab6b0382c9f176827c6f343aa4d64f7bc74e491
@@ -20,6 +20,17 @@ module SteamCodec
20
20
  attr_reader :SharedDepots
21
21
  attr_reader :CheckGuid
22
22
  attr_reader :InstallScripts
23
+ def self.scalarFields
24
+ return [:AppID, :Universe, :StateFlags, :InstallDir,
25
+ :LastUpdated, :UpdateResult, :SizeOnDisk,
26
+ :BuildID, :LastOwner, :BytesToDownload,
27
+ :BytesDownloaded, :FullValidateOnNextUpdate]
28
+ end
29
+
30
+ def self.extendedFields
31
+ return [:UserConfig, :MountedDepots, :SharedDepots, :CheckGuid, :InstallScripts]
32
+ end
33
+
23
34
  def self.loadFromFile(file)
24
35
  acf = KeyValues::loadFromFile(file)
25
36
  return self.new(acf.AppState) if acf and acf.key?(:AppState)
@@ -67,6 +78,37 @@ module SteamCodec
67
78
  @InstallScripts = InstallScripts.new(installScripts)
68
79
  end
69
80
 
81
+ def get(path = '', seperator = '.')
82
+ return nil unless @AppState
83
+ fields = path.split(seperator)
84
+ first = fields.shift
85
+ return to_hash unless first
86
+ self.class.scalarFields.each do |field|
87
+ if field.to_s.downcase == first.downcase
88
+ return self.send(field)
89
+ end
90
+ end
91
+ self.class.extendedFields.each do |field|
92
+ if field.to_s.downcase == first.downcase
93
+ return self.send(field).to_hash if fields.count == 0
94
+ return self.send(field).get(fields.join(seperator), seperator)
95
+ end
96
+ end
97
+ @AppState.get(path, seperator)
98
+ end
99
+
100
+ def to_hash
101
+ result = {}
102
+ self.class.scalarFields.each do |field|
103
+ result[field.to_s] = self.send(field)
104
+ end
105
+ self.class.extendedFields.each do |field|
106
+ result[field.to_s] = self.send(field)
107
+ result[field.to_s] = result[field.to_s].to_hash if result[field.to_s]
108
+ end
109
+ result
110
+ end
111
+
70
112
  class UserConfig
71
113
  attr_accessor :Name
72
114
  attr_accessor :GameID
@@ -74,6 +116,10 @@ module SteamCodec
74
116
  attr_accessor :AppInstallDir
75
117
  attr_accessor :Language
76
118
  attr_accessor :BetaKey
119
+ def self.scalarFields
120
+ return [:Name, :GameID, :Installed, :AppInstallDir, :Language, :BetaKey]
121
+ end
122
+
77
123
  def initialize(userConfig = nil)
78
124
  load(userConfig || KeyValues.new)
79
125
  end
@@ -88,6 +134,26 @@ module SteamCodec
88
134
  @Language = @UserConfig.language if @UserConfig.key?(:language)
89
135
  @BetaKey = @UserConfig.BetaKey if @UserConfig.key?(:BetaKey)
90
136
  end
137
+
138
+ def get(path = '', seperator = '.')
139
+ return nil unless @UserConfig
140
+ fields = path.split(seperator)
141
+ return to_hash unless fields.first
142
+ self.class.scalarFields.each do |field|
143
+ if field.to_s.downcase == fields.first.downcase
144
+ return self.send(field)
145
+ end
146
+ end
147
+ @UserConfig.get(path, seperator)
148
+ end
149
+
150
+ def to_hash
151
+ result = {}
152
+ self.class.scalarFields.each do |field|
153
+ result[field.to_s] = self.send(field)
154
+ end
155
+ result
156
+ end
91
157
  end
92
158
 
93
159
  class MountedDepots
@@ -103,6 +169,10 @@ module SteamCodec
103
169
  end
104
170
  end
105
171
 
172
+ def get(path = '', seperator = '.')
173
+ @MountedDepots[path.to_i]
174
+ end
175
+
106
176
  def depots
107
177
  @MountedDepots.keys
108
178
  end
@@ -132,6 +202,10 @@ module SteamCodec
132
202
  def remove(depot)
133
203
  @MountedDepots.delete(depot)
134
204
  end
205
+
206
+ def to_hash
207
+ @MountedDepots
208
+ end
135
209
  end
136
210
 
137
211
  class SharedDepots
@@ -148,6 +222,10 @@ module SteamCodec
148
222
  end
149
223
  end
150
224
 
225
+ def get(path = '', seperator = '.')
226
+ @SharedDepots[path.to_i]
227
+ end
228
+
151
229
  def depots
152
230
  @SharedDepots.keys
153
231
  end
@@ -166,6 +244,10 @@ module SteamCodec
166
244
  def remove(depot)
167
245
  @SharedDepots.delete(depot)
168
246
  end
247
+
248
+ def to_hash
249
+ @SharedDepots
250
+ end
169
251
  end
170
252
 
171
253
  class CheckGuid < ValueArray
@@ -104,8 +104,9 @@ module SteamCodec
104
104
  self.loadFromJSON(json)
105
105
  end
106
106
 
107
- def get(path = '')
108
- fields = path.gsub(/^\/|\/$/, '').split('/')
107
+ def get(path = '', seperator = '/')
108
+ escaped = Regexp.quote(seperator)
109
+ fields = path.gsub(/^#{escaped}|#{escaped}$/, '').split(seperator)
109
110
  current = self
110
111
  fields.each do |name|
111
112
  return nil if not current.key?(name)
@@ -39,6 +39,14 @@ module SteamCodec
39
39
  check
40
40
  end
41
41
 
42
+ def get(path = '', seperator = '.')
43
+ @ValueHash[path.to_i]
44
+ end
45
+
46
+ def to_hash
47
+ @ValueHash
48
+ end
49
+
42
50
  alias_method :all, :to_a
43
51
  alias_method :get, :[]
44
52
  alias_method :set, :[]=
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module SteamCodec
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
@@ -50,6 +50,20 @@ describe SteamCodec::ACF do
50
50
  EOS
51
51
  }
52
52
 
53
+ describe '.scalarFields' do
54
+ it 'should return array of fields' do
55
+ SteamCodec::ACF::scalarFields.should be_an_instance_of Array
56
+ SteamCodec::ACF::scalarFields.first.should be_an_instance_of Symbol
57
+ end
58
+ end
59
+
60
+ describe '.extendedFields' do
61
+ it 'should return array of fields' do
62
+ SteamCodec::ACF::extendedFields.should be_an_instance_of Array
63
+ SteamCodec::ACF::extendedFields.first.should be_an_instance_of Symbol
64
+ end
65
+ end
66
+
53
67
  describe '.loadFromFile' do
54
68
  it 'should successfully load from file' do
55
69
  StringIO.open(appCacheFile) do |file|
@@ -72,18 +86,60 @@ describe SteamCodec::ACF do
72
86
 
73
87
  describe '#InstallDir' do
74
88
  it 'should return value' do
75
- SteamCodec::ACF::load(appCacheFile).InstallDir.should eq("sacred_citadel")
89
+ SteamCodec::ACF::load(appCacheFile).InstallDir.should eq('sacred_citadel')
90
+ end
91
+ end
92
+
93
+ describe '#get' do
94
+ it 'should return value for scalar field' do
95
+ SteamCodec::ACF::load(appCacheFile).get('InstallDir').should eq('sacred_citadel')
96
+ end
97
+
98
+ it 'should return value for extended field' do
99
+ SteamCodec::ACF::load(appCacheFile).get('UserConfig.Name').should eq('Sacred Citadel')
100
+ end
101
+
102
+ it 'should return nil for unknown field' do
103
+ SteamCodec::ACF::load(appCacheFile).get('test').should be_nil
104
+ end
105
+ end
106
+
107
+ describe '#to_hash' do
108
+ it 'should return hash for all fields' do
109
+ SteamCodec::ACF::load(appCacheFile).to_hash.should be_an_instance_of Hash
76
110
  end
77
111
  end
78
112
 
79
113
  describe SteamCodec::ACF::UserConfig do
114
+
115
+ let(:config) { SteamCodec::ACF::UserConfig.new(SteamCodec::KeyValues[{"Name" => "Game"}]) }
116
+
117
+ describe '.scalarFields' do
118
+ it 'should return array of fields' do
119
+ SteamCodec::ACF::UserConfig::scalarFields.should be_an_instance_of Array
120
+ SteamCodec::ACF::UserConfig::scalarFields.first.should be_an_instance_of Symbol
121
+ end
122
+ end
123
+
80
124
  describe '.new' do
81
125
  it 'should initialize new instance with empty fields' do
82
126
  SteamCodec::ACF::UserConfig.new.Name.should be_nil
83
127
  end
84
128
 
85
129
  it 'should initialize new instance with provided fields' do
86
- SteamCodec::ACF::UserConfig.new(SteamCodec::KeyValues[{"Name" => "Game"}]).Name.should eq("Game")
130
+ config.Name.should eq("Game")
131
+ end
132
+ end
133
+
134
+ describe '#get' do
135
+ it 'should return nil for unknown field' do
136
+ config.get('test').should be_nil
137
+ end
138
+ end
139
+
140
+ describe '#to_hash' do
141
+ it 'should return hash for all fields' do
142
+ config.to_hash.should be_an_instance_of Hash
87
143
  end
88
144
  end
89
145
  end
@@ -180,6 +180,10 @@ describe SteamCodec::KeyValues do
180
180
  it 'should be nil if field doesn\'t exist' do
181
181
  keyValues.get('AppState/Something').should be_nil
182
182
  end
183
+
184
+ it 'should work with dot as seperator' do
185
+ keyValues.get('AppState.UserConfig.name', '.').should eq("Brütal Legend")
186
+ end
183
187
  end
184
188
 
185
189
  describe '#asArray' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steam_codec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dāvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: insensitive_hash