Class: Oculus::Storage::FileStore::File
- Inherits:
-
File
- Object
- File
- Oculus::Storage::FileStore::File
- Defined in:
- lib/oculus/storage/file_store.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #results ⇒ Object
- #write_prelude(attributes) ⇒ Object
- #write_results(results) ⇒ Object
Class Method Details
.parse(path) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/oculus/storage/file_store.rb', line 72 def self.parse(path) file = File.open(path, 'r:UTF-8') file.flock(File::LOCK_EX) attributes = file.attributes attributes[:results] = file.results file.flock(File::LOCK_UN) attributes[:id] = File.basename(path).split('.').first.to_i attributes[:starred] ||= false attributes end |
Instance Method Details
#attributes ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/oculus/storage/file_store.rb', line 101 def attributes rewind raw = gets until (line = gets) == "---\n" raw += line end YAML.load(raw) end |
#results ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/oculus/storage/file_store.rb', line 113 def results rewind section = 0 section += 1 if gets.rstrip == "---" until section == 2 || eof? CSV.new(read).to_a end |
#write_prelude(attributes) ⇒ Object
85 86 87 88 |
# File 'lib/oculus/storage/file_store.rb', line 85 def write_prelude(attributes) write(YAML.dump(attributes)) puts("---") end |
#write_results(results) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/oculus/storage/file_store.rb', line 90 def write_results(results) csv_data = CSV.generate(:encoding => 'UTF-8') do |csv| csv << results.first results[1..-1].each do |result| csv << result end end write csv_data end |