class TokyoMetro::Factory::Decorate::Api::TrainLocation::Info

Attributes

place_id[R]
railway_line[R]

Public Class Methods

new( request , obj , railway_line ) click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 3
def initialize( request , obj , railway_line )
  super( request , obj )
  @railway_line = railway_line
  set_station_infos
  set_place_id
end

Public Instance Methods

render() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 13
  def render
    h_locals_i = {
      this: self ,
      railway_line_of_train: railway_line_of_train ,
      train_type_decorated: train_type_decorated ,
      starting_station_decorated: starting_station_decorated ,
      terminal_station_decorated: terminal_station_decorated ,
      train_owner_decorated: train_owner_decorated ,
      to_render_train_type: render_train_type? ,
      to_render_train_owner: render_train_owner?
    }
    h.render inline: <<-HAML , type: :haml , locals: h_locals_i
%li{ class: [ :train_location , railway_line_of_train.css_class_name , :clearfix ] , id: this.object.train_number.downcase }
  %div{ class: :train_fundamental_infos }
    = railway_line_of_train.decorate.render_matrix( make_link_to_railway_line: false , size: :very_small )
    - if to_render_train_type
      = train_type_decorated.render_in_train_location
    = terminal_station_decorated.render_as_terminal_station
  = this.render_current_position
  %ul{ class: :sub_infos }
    = this.render_delay
    = this.render_train_number
    = starting_station_decorated.render_as_starting_station
    - if to_render_train_owner
      = train_owner_decorated.in_train_location.render
    HAML
  end
render_current_position() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 41
  def render_current_position
    h.render inline: <<-HAML , type: :haml , locals: { request: request , station_infos: @station_infos }
%div{ class: :current_position }
  %p{ class: [ :title_of_current_position , :text_ja ] }
    = "現在位置"
    %span{ class: :text_en }<
      = "Now at"
  %div{ class: :station_infos }<
    - station_infos.each.with_index(1) do | station_info , i |
      = station_info.decorate.train_location.render_name
      - unless i == station_infos.length
        %div{ class: :arrow }
          = ::TokyoMetro::App::Renderer::Icon.caret_down( request , 2 ).render
    HAML
  end
render_delay() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 57
def render_delay
  object.delay_instance.decorate( request ).render_in_location_of_each_train
end
render_train_number() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 61
  def render_train_number
    str = object.train_number
    h.render inline: <<-HAML , type: :haml , locals: { str: str }
%li{ class: [ :train_number , :sub_info , :clearfix ] }
  %div{ class: :title_of_train_number }
    %p{ class: :text_ja }<
      = "列車番号"
    %p{ class: :text_en }<
      = "Train number "
  %div{ class: [ :train_number_text , :text_en ] }<
    = str
    HAML
  end

Private Instance Methods

not_render_train_owner?() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 108
def not_render_train_owner?
  on_ginza_line_page? or on_marunouchi_line_page? or on_marunouchi_branch_line_page?
end
not_render_train_type?() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 104
def not_render_train_type?
  ( on_ginza_line_page? or on_marunouchi_line_page? or on_marunouchi_branch_line_page? or on_hibiya_line_page? ) and object.local_train?
end
railway_line_of_train() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 112
def railway_line_of_train
  if object.toei_mita_line?
    ::RailwayLine.find_by( same_as: "odpt.Railway:Toei.Mita" )
  else
    @railway_line
  end
end
set_place_id() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 93
def set_place_id
  case @station_infos.length
  when 1
    @place_id = "at_#{ @station_infos.first.name_in_system }"
  when 2
    @place_id = "from_#{ @station_infos.first.name_in_system }_to_#{ @station_infos.last.name_in_system }"
  else
    raise
  end
end
set_station_infos() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 77
def set_station_infos
  ary = [ :from_station , :to_station ].map { | attr_name |
    object.send( attr_name )
  }.select( &:present? ).map { | station_info_same_as |
    case station_info_same_as
    when "odpt.Station:TokyoMetro.Chiyoda.KitaAyase"
      "odpt.Station:TokyoMetro.ChiyodaBranch.KitaAyase"
    else
      station_info_same_as
    end
  }.map { | station_info_same_as |
    ::Station::Info.find_by( same_as: station_info_same_as )
  }
  @station_infos = ary
end
train_owner_decorated() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 166
def train_owner_decorated
  train_owner_in_db.decorate
end
train_owner_in_db() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 162
def train_owner_in_db
  ::TrainOwner.find_by( same_as: object.train_owner )
end
train_type() click to toggle source
# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 148
def train_type
  ::TokyoMetro::Factory::Decorate::Api::TrainLocation::Info::TrainType.get( self )
end
train_type_decorated() click to toggle source

else end

# File lib/tokyo_metro/factory/decorate/api/train_location/info.rb, line 158
def train_type_decorated
  train_type.decorate
end