aboutsummaryrefslogtreecommitdiffstats
path: root/app/presenters/time_table_presenter.rb
diff options
context:
space:
mode:
authorLuc Donnet2015-01-15 16:40:30 +0100
committerLuc Donnet2015-01-15 16:40:30 +0100
commitc89c3508eb953e79165ba61aee878db8e4d15ff5 (patch)
treef59b362c96c13bd5facba44f356676f3383e6cd3 /app/presenters/time_table_presenter.rb
parentb9a4d3cde1604f4bea01551d8c85624a313a2dfe (diff)
parent7d984efe77efd8e610c91fcefc35c4a3e17412fd (diff)
downloadchouette-core-c89c3508eb953e79165ba61aee878db8e4d15ff5.tar.bz2
Fix tests and merge master
Diffstat (limited to 'app/presenters/time_table_presenter.rb')
-rw-r--r--app/presenters/time_table_presenter.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/presenters/time_table_presenter.rb b/app/presenters/time_table_presenter.rb
new file mode 100644
index 000000000..140087c4f
--- /dev/null
+++ b/app/presenters/time_table_presenter.rb
@@ -0,0 +1,52 @@
+class TimeTablePresenter
+
+ def initialize(time_table)
+ @time_table = time_table
+ end
+
+ def time_table_state_code
+ if @time_table.validity_out_from_on?(Date.today)
+ "validity_out"
+ elsif @time_table.validity_out_between?(Date.today,Date.today+7.day)
+ "validity_out_soon"
+ else
+ "validity_regular"
+ end
+ end
+
+ def tag_list_shortened
+ @time_table.tags.join(', ').truncate(30, separator: ',')
+ end
+
+ def time_table_bounding
+ return I18n.t('time_tables.time_table.empty') if @time_table.bounding_dates.empty?
+ "#{I18n.l(@time_table.bounding_dates.min)} #{I18n.l(@time_table.bounding_dates.max)}"
+ end
+
+ def time_tables_shortest_info
+ return I18n.t('time_tables.time_table.empty') if @time_table.bounding_dates.empty?
+ "#{I18n.l(@time_table.bounding_dates.min)} #{I18n.l(@time_table.bounding_dates.max)}"
+ end
+
+ def composition_info
+ return if @time_table.bounding_dates.empty?
+ if @time_table.dates.empty?
+ I18n.t('time_tables.time_table.periods_count', :count => @time_table.periods.count)
+ elsif @time_table.periods.empty?
+ I18n.t('time_tables.time_table.dates_count', :count => @time_table.dates.count)
+ else
+ I18n.t('time_tables.time_table.periods_dates_count',
+ :dates_count => @time_table.dates.count,
+ :periods_count => @time_table.periods.count)
+ end
+ end
+
+private
+ def bounding_info
+ return I18n.t('time_tables.time_table.empty') if @time_table.bounding_dates.empty?
+ I18n.t('time_tables.time_table.bounding',
+ :start => l(@time_table.bounding_dates.min),
+ :end => l(@time_table.bounding_dates.max))
+ end
+
+end