Class: Woods::Feedback::Store
- Inherits:
-
Object
- Object
- Woods::Feedback::Store
- Defined in:
- lib/woods/feedback/store.rb
Overview
Append-only JSONL file for retrieval feedback: ratings and gap reports.
Each line is a JSON object with a ‘type` field (“rating” or “gap”) plus type-specific fields.
Instance Method Summary collapse
-
#all_entries(limit: nil) ⇒ Array<Hash>
Read all feedback entries.
-
#average_score ⇒ Float?
Average score across all ratings.
-
#gaps ⇒ Array<Hash>
Filter to gap report entries only.
-
#initialize(path:) ⇒ Store
constructor
A new instance of Store.
-
#ratings ⇒ Array<Hash>
Filter to rating entries only.
-
#record_gap(query:, missing_unit:, unit_type:) ⇒ void
Record a missing unit gap report.
-
#record_rating(query:, score:, comment: nil) ⇒ void
Record a retrieval quality rating.
Constructor Details
#initialize(path:) ⇒ Store
Returns a new instance of Store.
21 22 23 |
# File 'lib/woods/feedback/store.rb', line 21 def initialize(path:) @path = path end |
Instance Method Details
#all_entries(limit: nil) ⇒ Array<Hash>
Read all feedback entries.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/woods/feedback/store.rb', line 67 def all_entries(limit: nil) return [] unless File.exist?(@path) entries = [] File.foreach(@path) do |line| entry = JSON.parse(line.strip) entries << entry break if limit && entries.size >= limit rescue JSON::ParserError next end entries end |
#average_score ⇒ Float?
Average score across all ratings.
98 99 100 101 102 103 |
# File 'lib/woods/feedback/store.rb', line 98 def average_score scores = .map { |r| r['score'] } return nil if scores.empty? scores.sum.to_f / scores.size end |
#gaps ⇒ Array<Hash>
Filter to gap report entries only.
91 92 93 |
# File 'lib/woods/feedback/store.rb', line 91 def gaps all_entries.select { |e| e['type'] == 'gap' } end |
#ratings ⇒ Array<Hash>
Filter to rating entries only.
84 85 86 |
# File 'lib/woods/feedback/store.rb', line 84 def all_entries.select { |e| e['type'] == 'rating' } end |
#record_gap(query:, missing_unit:, unit_type:) ⇒ void
This method returns an undefined value.
Record a missing unit gap report.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/woods/feedback/store.rb', line 52 def record_gap(query:, missing_unit:, unit_type:) entry = { type: 'gap', query: query, missing_unit: missing_unit, unit_type: unit_type, timestamp: Time.now.iso8601 } append(entry) end |
#record_rating(query:, score:, comment: nil) ⇒ void
This method returns an undefined value.
Record a retrieval quality rating.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/woods/feedback/store.rb', line 31 def (query:, score:, comment: nil) unless score.is_a?(Integer) && (1..5).cover?(score) raise ArgumentError, "score must be an Integer between 1 and 5, got: #{score.inspect}" end entry = { type: 'rating', query: query, score: score, comment: comment, timestamp: Time.now.iso8601 } append(entry) end |