Class: Z4BC::User

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i) ⇒ User

Returns a new instance of User.



140
141
142
143
144
145
# File 'lib/z4blockchain.rb', line 140

def initialize i
  @id = i
  @game = PStore.new("db/player-game-#{i}.pstore")
  @wins = PStore.new("db/player-wins-#{i}.pstore")
  @lvls = PStore.new("db/player-lvls-#{i}.pstore")
end

Instance Attribute Details

#gameObject (readonly)

Returns the value of attribute game.



138
139
140
# File 'lib/z4blockchain.rb', line 138

def game
  @game
end

#idObject

Returns the value of attribute id.



136
137
138
# File 'lib/z4blockchain.rb', line 136

def id
  @id
end

#lvlsObject (readonly)

Returns the value of attribute lvls.



138
139
140
# File 'lib/z4blockchain.rb', line 138

def lvls
  @lvls
end

#winsObject (readonly)

Returns the value of attribute wins.



138
139
140
# File 'lib/z4blockchain.rb', line 138

def wins
  @wins
end

Instance Method Details

#to_hObject



147
148
149
150
151
152
153
# File 'lib/z4blockchain.rb', line 147

def to_h
  h = { game: {}, wins: {}, lvls: {} }
  @game.transaction { |db| db.keys.each { |e| h[:game][e] = db[e] } }
  @wins.transaction { |db| db.keys.each { |e| h[:wins][e] = db[e] } }
  @lvls.transaction { |db| db.keys.each { |e| h[:lvls][e] = db[e] } }
  return h
end