class TokyoMetro::App::Renderer::StationTimetable::Group::EachRailwayLine::EachRailwayDirection::EachOperationDay::StationTrainTimes

Attributes

car_compositions[R]
grouped_by_hour[R]
major_terminal_station_info_id[R]
terminal_station_infos[R]
train_type_infos[R]

Public Class Methods

new( station_train_times ) click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 3
def initialize( station_train_times )
  @grouped_by_hour = station_train_times.group_by( &:hour_in_station_timetable )

  @terminal_station_infos = ::Station::Info.where( id: terminal_station_info_ids )
  @train_type_infos = ::TrainType.includes( :train_type_in_api ).where( id: train_type_info_ids )
  @car_compositions = ids_in_station_train_times( :car_composition ).select( &:present? )
  @major_terminal_station_info_id = get_major_terminal_station_info_id
end

Public Instance Methods

has_one_terminal_station_info?() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 18
def has_one_terminal_station_info?
  @terminal_station_infos.length == 1
end
has_one_train_type_info?() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 22
def has_one_train_type_info?
  @train_type_infos.map( &:train_type_in_api ).map( &:id ).uniq.length == 1
end
hours() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 26
def hours
  midnight_hours = [ 0 , 1 , 2 ]
  a = @grouped_by_hour.keys.sort

  midnight_hours.each do | midnight_hour |
    if a.include?( midnight_hour )
      a = a - [ midnight_hour ]
      a = a + [ midnight_hour ]
    end
  end

  a
end
render_body() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 40
  def render_body
    h.render inline: <<-HAML , type: :haml , locals: h_locals
- one_terminal_station_info = this.has_one_terminal_station_info?
- one_train_type_info = this.has_one_train_type_info?
%tbody
  - this.hours.each do |h|
    - station_train_times_in_an_hour = this.grouped_by_hour[h].sort_by( &:min_in_station_timetable )
    %tr{ class: :hour_row }
      %td{ class: :hour }<
        = h
      %td{ class: [ :station_train_times , cycle( :odd , :even ) ] }
        - station_train_times_in_an_hour.each do | station_train_time |
          = station_train_time.decorate.render_in_station_timetable( this.terminal_station_infos , this.train_type_infos , one_train_type_info , one_terminal_station_info , this.major_terminal_station_info_id )
    HAML
  end
render_message_in_header() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 56
  def render_message_in_header
    h.render inline: <<-HAML , type: :haml , locals: { ja: message_in_header_ja , en: message_in_header_en }
%tr
  %td{ colspan: 2 , class: :train_type_and_terminal_station_infos }<
    %div{ class: :text_ja }<
      = ja
    %div{ class: :text_en }<
      = en
    HAML
  end

Private Instance Methods

ary() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 69
def ary
  @grouped_by_hour.values.flatten
end
get_major_terminal_station_info_id() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 85
def get_major_terminal_station_info_id
  nishi_takashimadaira_id = ::Station::Info.find_by( same_as: "odpt.Station:Toei.Mita.NishiTakashimadaira" ).id
  terminal_station_info_ids.delete_if { |n| n == nishi_takashimadaira_id }.max { | terminal_station_info_id_1 , terminal_station_info_id_2 |
    number_of_trains_for( terminal_station_info_id_1 ) <=> number_of_trains_for( terminal_station_info_id_2 )
  }
end
h_locals() click to toggle source
Calls superclass method
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 96
def h_locals
  super.merge({
    this: self
  })
end
ids_in_station_train_times( method_name ) click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 73
def ids_in_station_train_times( method_name )
  ary.map { | station_train_time | station_train_time.send( method_name ) }.uniq
end
major_terminal_station_info() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 159
def major_terminal_station_info
  @terminal_station_infos.find_by( id: @major_terminal_station_info_id )
end
message_in_header_en() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 130
def message_in_header_en
  str = ::String.new
  one_terminal_station_info = has_one_terminal_station_info?
  one_train_type_info = has_one_train_type_info?
  if one_terminal_station_info or one_train_type_info
    str << "All trains are"
    if one_train_type_info
      str << " "
      str << @train_type_infos.first.train_type_in_api.name_en
    end
    if one_terminal_station_info
      str << " "
      str << "bound for "
      str << @terminal_station_infos.first.name_en
    end
    str << "."
    unless one_terminal_station_info
      str << " "
    end
  end

  unless one_terminal_station_info
    str << "All trains with no description of destination are bound for "
    str << major_terminal_station_info.name_en
    str << "."
  end
  str
end
message_in_header_ja() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 102
def message_in_header_ja
  str = ::String.new
  one_terminal_station_info = has_one_terminal_station_info?
  one_train_type_info = has_one_train_type_info?
  if one_terminal_station_info or one_train_type_info
    str << "列車はすべて "
    if one_train_type_info
      str << @train_type_infos.first.train_type_in_api.name_ja
      str << " "
    end
    if one_terminal_station_info
      str << @terminal_station_infos.first.name_ja
      str << " 行き "
    end
    str << "です。"
    unless one_terminal_station_info
      str << "なお、"
    end
  end

  unless one_terminal_station_info
    str << "行先の記載がない列車はすべて "
    str << major_terminal_station_info.name_ja
    str << " 行きです。"
  end
  str
end
number_of_trains_for( station_info_id ) click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 92
def number_of_trains_for( station_info_id )
  ary.count { | station_train_time | station_train_time.terminal_station_info_id == station_info_id }
end
terminal_station_info_ids() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 77
def terminal_station_info_ids
  ids_in_station_train_times( :terminal_station_info_id )
end
train_type_info_ids() click to toggle source
# File lib/tokyo_metro/app/renderer/station_timetable/group/each_railway_line/each_direction/each_operation_day/station_train_times.rb, line 81
def train_type_info_ids
  ids_in_station_train_times( :train_type_id )
end