Class: TokyoMetro::Factory::Decorate::Api::TrainOperation::Info

Inherits:
Common show all
Defined in:
lib/tokyo_metro/factory/decorate/api/train_operation/info.rb

Defined Under Namespace

Classes: BasicError, JsonParserError, NetworkError

Instance Attribute Summary

Attributes inherited from Common

#controller, #railway_line, #status_type

Attributes inherited from MetaClass::RealTime::Info

#object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Common

#render, #render_status_icon_and_text

Constructor Details

#initialize(request, obj, railway_line, max_delay, controller, no_train) ⇒ Info

Returns a new instance of Info.



3
4
5
6
7
8
9
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 3

def initialize( request , obj , railway_line , max_delay , controller , no_train )
  super( request , obj , railway_line , controller )
  set_max_delay( max_delay )
  @no_train = no_train

  @status_type = status_type_on_initialize
end

Class Method Details

.render_status_icon_and_text(request, status_type, icon_size = 3) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 139

def self.render_status_icon_and_text( request , status_type , icon_size = 3 )
  h_locals_i = {
    request: request ,
    status_type: status_type ,
    icon_size: icon_size
  }
  h.render inline: <<-HAML , type: :haml , locals: { this: self }
%div{ class: :icon }<
= ::TokyoMetro::App::Renderer::Icon.send( this.status_type , request , 3 ).render
%div{ class: :text }
%p{ class: :text_ja }<
  = this.status_text_ja
%p{ class: :text_en }<
  = this.status_text_en
  HAML
end

Instance Method Details

#additional_info_abstruct_enObject



19
20
21
22
23
24
25
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 19

def additional_info_abstruct_en
  if actually_delayed?
    nil
  else
    object.train_operation_status.try( :name_en_for_display )
  end
end

#additional_info_abstruct_jaObject



11
12
13
14
15
16
17
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 11

def additional_info_abstruct_ja
  if actually_delayed?
    nil
  else
    object.train_operation_status.try( :name_ja_for_display )
  end
end

#additional_info_precise_enObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 48

def additional_info_precise_en
  case @status_type
  when :after_last_train_finished
    "Today's operation was finished."
  when :before_first_train_begin
    "Please wait for the first train."
  when :no_train
    "No train is operated now."
  else
    if actually_delayed?
      nil
    else
      object.text_en
    end
  end
end

#additional_info_precise_jaObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 27

def additional_info_precise_ja
  case @status_type
  when :after_last_train_finished
    "本日の運行は終了しました。"
  when :before_first_train_begin
    "運行開始までお待ち下さい。"
  when :no_train
    "運行中の列車はありません。"
  else
    if actually_delayed?
      nil
    else
      object.text_in_api
    end
  end
end

#additional_info_precise_ja_to_aObject



44
45
46
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 44

def additional_info_precise_ja_to_a
  additional_info_precise_ja.try( :split , /\n/ )
end

#render_status_additional_infosObject

Note:

親クラスで定義済

def render end def render_status_icon_and_text end



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 105

def render_status_additional_infos
  h_locals_i = {
    this: self ,
    max_delay_decorator: max_delay_decorator ,
    to_render_status_additional_infos_ja: to_render_status_additional_infos_ja? ,
    to_render_status_additional_infos_en: to_render_status_additional_infos_en?
  }
  h.render inline: <<-HAML , type: :haml , locals: h_locals_i
%div{ class: :additional_infos }<
- if to_render_status_additional_infos_ja
  %div{ class: :text_ja }
    - if this.additional_info_abstruct_ja.present?
      %p{ class: :abstruct }<
        = this.additional_info_abstruct_ja
    - if max_delay_decorator.try( :displayed_in_train_operation_info? )
      = max_delay_decorator.render_ja_in_train_operation_info
    - if this.additional_info_precise_ja_to_a.present?
      - this.additional_info_precise_ja_to_a.each do | row |
        %p{ class: :precise }<
          = row

- if to_render_status_additional_infos_en
  %div{ class: :text_en }
    - if this.additional_info_abstruct_en.present?
      %p{ class: :abstruct }<
        = this.additional_info_abstruct_en
    - if max_delay_decorator.displayed_in_train_operation_info?
      = max_delay_decorator.render_en_in_train_operation_info
    - if this.additional_info_precise_en.present?
      %p{ class: :precise }<
        = this.additional_info_precise_en
  HAML
end

#status_text_enObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 82

def status_text_en
  case status_type
  when :no_train , :after_last_train_finished , :before_first_train_begin
    "No train is operated now."
  when :on_schedule
    "Now on schedule"
  when :nearly_on_schedule
    "Now on schedule"
  when :delayed
    "Delayed"
  when :suspended
    "Operation suspended"
  when :other_status
    "Information"
  end
end

#status_text_jaObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/tokyo_metro/factory/decorate/api/train_operation/info.rb', line 65

def status_text_ja
  case status_type
  when :no_train , :after_last_train_finished , :before_first_train_begin
    "運行中の列車 なし"
  when :on_schedule
    "平常運転"
  when :nearly_on_schedule
    "ほぼ平常運転"
  when :delayed
    "遅れあり"
  when :suspended
    "運転見合わせ"
  when :other_status
    "お知らせ"
  end
end