Class: Buhos::AnalysisCdDecisions
- Inherits:
-
Object
- Object
- Buhos::AnalysisCdDecisions
- Defined in:
- lib/buhos/analysis_cd_decisions.rb
Overview
Analysis of decision by cd
Instance Method Summary collapse
-
#all_allocations ⇒ Object
@all_allocations=all_allocations.
- #all_decisions ⇒ Object
-
#initialize(sr, stage) ⇒ AnalysisCdDecisions
constructor
A new instance of AnalysisCdDecisions.
- #text_decision_cd(cd_id, dec) ⇒ Object
- #to_html(cd_id) ⇒ Object
- #to_text(cd_id) ⇒ Object
Constructor Details
#initialize(sr, stage) ⇒ AnalysisCdDecisions
Returns a new instance of AnalysisCdDecisions.
33 34 35 36 37 38 39 |
# File 'lib/buhos/analysis_cd_decisions.rb', line 33 def initialize(sr, stage) @sr = sr @stage = stage @all_decisions=all_decisions @user_names=@sr.group_users.inject({}) {|ac,v| ac[v[:id]]=v[:name];ac } #@all_allocations=all_allocations end |
Instance Method Details
#all_allocations ⇒ Object
@all_allocations=all_allocations
40 41 42 43 44 |
# File 'lib/buhos/analysis_cd_decisions.rb', line 40 def all_allocations cds=@sr.cd_id_by_stage(@stage) allocations=AllocationCd.where(:systematic_review_id=>@sr.id, :canonical_document_id=>cds, :stage=>@stage.to_s).select_hash_groups(:canonical_document_id, :user_id) allocations end |
#all_decisions ⇒ Object
45 46 47 48 49 |
# File 'lib/buhos/analysis_cd_decisions.rb', line 45 def all_decisions cds=@sr.cd_id_by_stage(@stage) decisions=Decision.where(:systematic_review_id=>@sr.id, :canonical_document_id=>cds, :user_id=>@sr.group_users.map {|u| u[:id]}, :stage=>@stage.to_s).to_hash_groups(:canonical_document_id) decisions end |
#text_decision_cd(cd_id, dec) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/buhos/analysis_cd_decisions.rb', line 91 def text_decision_cd(cd_id, dec) res=@all_decisions[cd_id].find_all {|v| v[:decision]==dec}.map {|v| v[:commentary].nil? ? "#{@user_names[v[:user_id]]}" : "#{@user_names[v[:user_id]]} : #{v[:commentary]}" } res.join(" | \n") end |
#to_html(cd_id) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/buhos/analysis_cd_decisions.rb', line 70 def to_html(cd_id) if @all_decisions.nil? or @all_decisions[cd_id].nil? return "" end res_raw=@all_decisions[cd_id].inject({}) do |ac,v| dec=v[:decision] ac[dec]||=[] text=v[:commentary].nil? ? @user_names[v[:user_id]] : "#{@user_names[v[:user_id]]} (#{v[:commentary]})" ac[dec].push(text) ac end out_html=res_raw.map do |dec,v| dec_name=I18n::t(Decision.get_name_decision(dec)) =v.map {|v| "<span class='decision-author'>#{v}</span>"} "<li><span class='decision-name'>#{dec_name}</span>: #{.join('; ')}</li>" end "<ul>\n#{out_html.join("\n")}\n</ul>" end |
#to_text(cd_id) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/buhos/analysis_cd_decisions.rb', line 51 def to_text(cd_id) if @all_decisions.nil? or @all_decisions[cd_id].nil? return "" end res_raw=@all_decisions[cd_id].inject({}) do |ac,v| dec=v[:decision] ac[dec]||=[] text=v[:commentary].nil? ? @user_names[v[:user_id]] : "#{@user_names[v[:user_id]]} (#{v[:commentary]})" ac[dec].push(text) ac end out_html=res_raw.map do |dec,v| dec_name=I18n::t(Decision.get_name_decision(dec)) =v.map {|v| "#{v}"} "**#{dec_name}** : #{.join('; ')} | " end "#{out_html.join("\n")}" end |