Class: Codebreaker::Statistic
- Inherits:
-
Object
- Object
- Codebreaker::Statistic
- Defined in:
- lib/codebreaker/statistic.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ Statistic
constructor
A new instance of Statistic.
- #read ⇒ Object
- #save(game) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Statistic
Returns a new instance of Statistic.
7 8 9 |
# File 'lib/codebreaker/statistic.rb', line 7 def initialize(file_path) @file_path = file_path end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/codebreaker/statistic.rb', line 5 def file_path @file_path end |
Instance Method Details
#read ⇒ Object
19 20 21 |
# File 'lib/codebreaker/statistic.rb', line 19 def read YAML.load_file(file_path) end |
#save(game) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/codebreaker/statistic.rb', line 11 def save(game) data = File.file?(file_path) && !File.zero?(file_path) ? read : [] data << new_record(game) file = File.open(file_path, 'w') file.write(data.to_yaml) file.close end |