aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authoranicet2015-06-11 17:55:11 +0200
committeranicet2015-06-16 10:45:53 +0200
commit095d03b2b2f36eab0e5b4713adeb051020b45401 (patch)
tree063c879a66ab6ee121e7908f58334635a84f1303 /app
parentce742caeb4c939f95e25cd0e0ac9f7a64ffe129c (diff)
downloadchouette-core-095d03b2b2f36eab0e5b4713adeb051020b45401.tar.bz2
ReportConcern : clean and add delegate
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/report_concern.rb69
1 files changed, 28 insertions, 41 deletions
diff --git a/app/models/concerns/report_concern.rb b/app/models/concerns/report_concern.rb
index 6c080578d..a71ae1855 100644
--- a/app/models/concerns/report_concern.rb
+++ b/app/models/concerns/report_concern.rb
@@ -3,14 +3,19 @@ module ReportConcern
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Model
-
- included do
+
+ included do
attr_reader :datas
end
module ClassMethods
end
+ delegate :progression?, to: :datas
+ delegate :progression, to: :datas
+ delegate :zip_file, to: :datas
+ delegate :stats, to: :datas
+
def failure_code?
datas.result == "NOK" && datas.failure?
end
@@ -18,19 +23,11 @@ module ReportConcern
def failure_code
datas.failure.code.downcase if failure_code?
end
-
- def progression?
- datas.progression?
- end
-
- def progression
- datas.progression
- end
def percentage(a, b)
(a.to_f / b.to_f * 100).round(0)
end
-
+
def level_progress
percentage( progression.current_step, progression.steps_count) if progression?
end
@@ -42,25 +39,21 @@ module ReportConcern
def current_step
datas.progression.steps[ progression.current_step - 1]
end
-
+
def step_progress
percentage( current_step.realized, current_step.total )
end
-
+
def step_progress_name
return last_step.step if progression.current_step == progression.steps_count
current_step.step
end
- def zip_file
- datas.zip_file
- end
-
def files
datas.files || []
end
-
+
def error_files
files.select{ |file| file[:status] == "ERROR"}
end
@@ -71,8 +64,8 @@ module ReportConcern
def ok_files
files.select{ |file| file[:status] == "OK"}
- end
-
+ end
+
def line_items
[].tap do |line_items|
datas.lines.each do |line|
@@ -81,46 +74,41 @@ module ReportConcern
end
end
- def stats
- datas.stats
- end
-
def lines
stats.present? ? stats.line_count : 0
end
-
+
def routes
stats.present? ? stats.route_count : 0
end
-
+
def connection_links
stats.present? ? stats.connection_link_count : 0
end
-
+
def time_tables
stats.present? ? stats.time_table_count : 0
end
-
+
def stop_areas
stats.present? ? stats.stop_area_count : 0
end
-
+
def access_points
stats.present? ? stats.access_point_count : 0
end
-
+
def vehicle_journeys
stats.present? ? stats.vehicle_journey_count : 0
end
-
+
def journey_patterns
stats.present? ? stats.journey_pattern_count : 0
end
-
-
+
class LineItem
attr_reader :options
-
+
def initialize( options )
@options = options
end
@@ -134,17 +122,17 @@ module ReportConcern
end
def status
- @status ||= if options.status?
+ @status ||= if options.status?
if %w{ok warning}.include? options.status.downcase
true
else
false
- end
+ end
else
false
end
- end
-
+ end
+
def routes
stats ? stats.route_count : 0
end
@@ -164,7 +152,7 @@ module ReportConcern
def access_points
stats ? stats.access_point_count : 0
end
-
+
def vehicle_journeys
stats ? stats.vehicle_journey_count : 0
end
@@ -173,6 +161,5 @@ module ReportConcern
stats ? stats.journey_pattern_count : 0
end
- end
-
+ end
end