Class: Ossert::Presenters::Project
- Inherits:
-
Object
- Object
- Ossert::Presenters::Project
show all
- Includes:
- ProjectV2
- Defined in:
- lib/ossert/presenters/project.rb
Defined Under Namespace
Classes: Decorator
Constant Summary
Constants included
from ProjectV2
Ossert::Presenters::ProjectV2::CLASSES, Ossert::Presenters::ProjectV2::KLASS_2_GRADE, Ossert::Presenters::ProjectV2::REFERENCES_STUB
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from ProjectV2
#fast_preview_graph_data, #last_quarters_bounds, #metric_tooltip_data, #preview_reference_values_for, #reversed_metrics, #sum_up_checks, #tooltip_data
Constructor Details
#initialize(project) ⇒ Project
Returns a new instance of Project.
11
12
13
14
15
|
# File 'lib/ossert/presenters/project.rb', line 11
def initialize(project)
@project = project
@reference = Ossert::Classifiers::Growing.current.reference_values_per_grade
@decorator = Decorator.new(@reference)
end
|
Instance Attribute Details
#decorator ⇒ Object
Returns the value of attribute decorator.
9
10
11
|
# File 'lib/ossert/presenters/project.rb', line 9
def decorator
@decorator
end
|
#fast_preview_graph ⇒ Object
Returns the value of attribute fast_preview_graph.
191
192
193
|
# File 'lib/ossert/presenters/project.rb', line 191
def fast_preview_graph
@fast_preview_graph
end
|
#grade ⇒ Object
Returns the value of attribute grade.
191
192
193
|
# File 'lib/ossert/presenters/project.rb', line 191
def grade
@grade
end
|
#project ⇒ Object
Returns the value of attribute project.
9
10
11
|
# File 'lib/ossert/presenters/project.rb', line 9
def project
@project
end
|
Class Method Details
.with_presenter(project) {|presenter| ... } ⇒ Object
17
18
19
20
21
22
|
# File 'lib/ossert/presenters/project.rb', line 17
def self.with_presenter(project)
presenter = new(project)
presenter.prepare!
yield(presenter)
presenter.cleanup_references!
end
|
Instance Method Details
#agility_last_year ⇒ Object
145
146
147
|
# File 'lib/ossert/presenters/project.rb', line 145
def agility_last_year
@agility_last_year ||= decorator.metrics @project.agility.quarters.last_year_as_hash, :agility_year
end
|
#agility_quarter(time) ⇒ Object
117
118
119
|
# File 'lib/ossert/presenters/project.rb', line 117
def agility_quarter(time)
decorator.quarter_with_diff(@project, time, :agility)
end
|
#agility_quarter_values(time) ⇒ Object
125
126
127
|
# File 'lib/ossert/presenters/project.rb', line 125
def agility_quarter_values(time)
decorator.quarter_values @project.agility.quarters[time].metrics_to_hash
end
|
#agility_total ⇒ Object
133
134
135
|
# File 'lib/ossert/presenters/project.rb', line 133
def agility_total
@agility_total ||= decorator.metrics @project.agility.total.metrics_to_hash, :agility_total
end
|
#cleanup_references! ⇒ Object
193
194
195
196
197
198
199
|
# File 'lib/ossert/presenters/project.rb', line 193
def cleanup_references!
@reference = nil
@project = nil
@fast_preview_graph_data = nil
@grade = nil
@decorator = nil
end
|
141
142
143
|
# File 'lib/ossert/presenters/project.rb', line 141
def
||= decorator.metrics @project..quarters.last_year_as_hash, :community_year
end
|
121
122
123
|
# File 'lib/ossert/presenters/project.rb', line 121
def (time)
decorator.quarter_with_diff(@project, time, :community)
end
|
129
130
131
|
# File 'lib/ossert/presenters/project.rb', line 129
def (time)
decorator.quarter_values @project..quarters[time].metrics_to_hash
end
|
137
138
139
|
# File 'lib/ossert/presenters/project.rb', line 137
def
||= decorator.metrics @project..total.metrics_to_hash, :community_total
end
|
#last_year_section(metric, section) ⇒ Object
161
162
163
164
165
166
167
|
# File 'lib/ossert/presenters/project.rb', line 161
def last_year_section(metric, section)
section_last_year = public_send("#{section}_last_year")[metric]
{
last_year_mark: section_last_year.try(:[], :mark),
last_year_val: section_last_year.try(:[], :text) || 'N/A'
}
end
|
#metric_preview(metric) ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/ossert/presenters/project.rb', line 149
def metric_preview(metric)
preview = {}
return(preview) if (section = Ossert::Stats.guess_section_by_metric(metric)) == :not_found
preview[:tooltip] = MultiJson.dump(tooltip_data(metric))
preview[:translation] = Ossert.t(metric)
preview.merge!(last_year_section(metric, section))
preview.merge!(total_section(metric, section))
preview
end
|
#prepare! ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/ossert/presenters/project.rb', line 177
def prepare!
agility_total
agility_last_year
lookback = 5
check_results = (lookback - 1).downto(0).map do |last_year_offset|
Ossert::Classifiers::Growing.current.check(@project, last_year_offset)
end
@grade = check_results.last(2).first.map { |k, v| [k, v[:mark].downcase] }.to_h
@fast_preview_graph = fast_preview_graph_data(lookback, check_results)
end
|
#total_section(metric, section) ⇒ Object
169
170
171
172
173
174
175
|
# File 'lib/ossert/presenters/project.rb', line 169
def total_section(metric, section)
section_total = public_send("#{section}_total")[metric]
{
total_mark: section_total.try(:[], :mark),
total_val: section_total.try(:[], :text) || 'N/A'
}
end
|