Module: Commenter::BallotDiff
- Defined in:
- lib/commenter/ballot_diff.rb
Overview
Stage-to-stage comparison of two ballots: how the comment set evolved between e.g. CD and DIS — new comments, withdrawn comments, repeated unchanged comments, and revised ones. Comments are matched by ID (member body + number), which repeats across stages.
Class Method Summary collapse
- .diff(before_sheet, after_sheet) ⇒ Object
- .dispositioned?(comment) ⇒ Boolean
- .identical?(before, after) ⇒ Boolean
- .indexed(sheet) ⇒ Object
- .to_markdown(before_sheet, after_sheet) ⇒ Object
Class Method Details
.diff(before_sheet, after_sheet) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/commenter/ballot_diff.rb', line 11 def diff(before_sheet, after_sheet) before_comments = indexed(before_sheet) after_comments = indexed(after_sheet) result = { new: [], withdrawn: [], repeated: [], revised: [], resolved: [] } after_comments.each do |id, after| before = before_comments[id] if before.nil? result[:new] << id elsif identical?(before, after) result[:repeated] << id else result[:revised] << id end result[:resolved] << id if dispositioned?(after) end before_comments.each_key { |id| result[:withdrawn] << id unless after_comments.key?(id) } result.each_value(&:sort!) result end |
.dispositioned?(comment) ⇒ Boolean
59 60 61 62 |
# File 'lib/commenter/ballot_diff.rb', line 59 def dispositioned?(comment) observation = comment.observations.to_s.strip !observation.empty? || DispositionStatus.match(comment.resolution_status) end |
.identical?(before, after) ⇒ Boolean
55 56 57 |
# File 'lib/commenter/ballot_diff.rb', line 55 def identical?(before, after) before.comments == after.comments && before.proposed_change == after.proposed_change end |
.indexed(sheet) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/commenter/ballot_diff.rb', line 48 def indexed(sheet) sheet.comments.each_with_object({}) do |comment, index| key = comment.id.to_s index[key] = comment unless key.empty? end end |
.to_markdown(before_sheet, after_sheet) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/commenter/ballot_diff.rb', line 33 def to_markdown(before_sheet, after_sheet) data = diff(before_sheet, after_sheet) lines = [] lines << "| Category | Count | Comments |" lines << "|----------|-------|----------|" data.each do |category, ids| label = category.to_s.tr("_", " ").capitalize listed = ids.length <= 10 ? ids.join(", ") : "#{ids.first(10).join(", ")} …" lines << "| #{label} | #{ids.length} | #{listed} |" end lines << "" lines << "Resolved (disposition recorded in the later stage): #{data[:resolved].length}" lines.join("\n") end |