@@ -11,10 +11,10 @@ def index
1111 flash [ :inline_alert ] = "指定された年は無効です。2012年から#{ Date . current . year } 年の間で指定してください。"
1212 return redirect_to dojos_path ( anchor : 'table' )
1313 end
14-
14+
1515 @selected_year = year
1616 year_end = Time . zone . local ( @selected_year ) . end_of_year
17-
17+
1818 # その年末時点でアクティブだった道場を取得
1919 dojos_scope = Dojo . active_at ( year_end )
2020 @page_title = "#{ @selected_year } 年末時点のCoderDojo一覧"
@@ -26,7 +26,7 @@ def index
2626 # yearパラメータなしの場合(既存の実装そのまま)
2727 dojos_scope = Dojo . all
2828 end
29-
29+
3030 @dojos = [ ]
3131 dojos_scope . includes ( :prefecture ) . order_by_active_status . order ( order : :asc ) . each do |dojo |
3232 # 年が選択されている場合は、その年末時点でのアクティブ状態を判定
@@ -38,7 +38,7 @@ def index
3838 else
3939 dojo . active?
4040 end
41-
41+
4242 @dojos << {
4343 id : dojo . id ,
4444 url : dojo . url ,
@@ -53,25 +53,25 @@ def index
5353 inactivated_at : dojo . inactivated_at , # CSV用に追加
5454 }
5555 end
56-
56+
5757 # counter合計を計算(/statsとの照合用)
5858 @counter_sum = @dojos . sum { |d | d [ :counter ] }
59-
59+
6060 # 情報メッセージを設定
6161 if @selected_year
6262 # /statsページと同じ計算方法を使用
6363 # 開設数 = その年に新規開設されたDojoのcounter合計
6464 year_begin = Time . zone . local ( @selected_year ) . beginning_of_year
6565 year_end = Time . zone . local ( @selected_year ) . end_of_year
6666 new_dojos_count = Dojo . where ( created_at : year_begin ..year_end ) . sum ( :counter )
67-
67+
6868 # 合計数 = その年末時点でアクティブだったDojoのcounter合計
6969 total_dojos_count = Dojo . active_at ( year_end ) . sum ( :counter )
70-
70+
7171 # 表示用の日付テキスト
7272 display_date = "#{ @selected_year } 年末"
7373 display_date = Date . current . strftime ( '%Y年%-m月%-d日' ) if @selected_year == Date . current . year
74-
74+
7575 flash . now [ :inline_info ] = "#{ display_date } 時点のアクティブな道場を表示中<br>(開設数: #{ new_dojos_count } / 合計数: #{ total_dojos_count } )" . html_safe
7676 else
7777 # 全期間表示時の情報メッセージ
@@ -111,34 +111,34 @@ def show
111111 def activity
112112 # ビューで使用するための閾値をインスタンス変数に設定(モデルから取得)
113113 @inactive_threshold = Dojo ::INACTIVE_THRESHOLD_IN_MONTH
114-
114+
115115 @latest_event_by_dojos = [ ]
116116 Dojo . active . each do |dojo |
117117 link_in_note = dojo . note . match ( URI . regexp )
118118 # YYYY-MM-DD、YYYY/MM/DD、または YYYY年MM月DD日 形式の日付を抽出
119119 date_in_note = dojo . note . match ( /(\d {4}-\d {1,2}-\d {1,2}|\d {4}\/ \d {1,2}\/ \d {1,2}|\d {4}年\d {1,2}月\d {1,2}日)/ )
120-
120+
121121 latest_event = dojo . event_histories . newest . first
122-
122+
123123 @latest_event_by_dojos << {
124124 id : dojo . id ,
125125 name : dojo . name ,
126126 note : dojo . note ,
127127 url : dojo . url ,
128128 created_at : dojo . created_at , # 掲載日(/dojos と同じ)
129-
129+
130130 # 直近の開催日(イベント履歴がある場合のみ)
131- latest_event_at : latest_event . nil? ? nil : latest_event . evented_at ,
132- latest_event_url : latest_event . nil? ? nil : latest_event . event_url ,
133-
131+ latest_event_at : latest_event & .evented_at ,
132+ latest_event_url : latest_event & .event_url ,
133+
134134 # note内の日付とリンク(fallback用)
135135 note_date : parse_date_from_note ( date_in_note ) ,
136- note_link : link_in_note . nil? ? nil : link_in_note . to_s
136+ note_link : link_in_note & .to_s
137137 }
138138 end
139139
140140 # Sort by latest event date (or created_at if no events) && Dojo's order if same date
141- @latest_event_by_dojos . sort_by! do |dojo |
141+ @latest_event_by_dojos . sort_by! do |dojo |
142142 sort_date = dojo [ :latest_event_at ] || dojo [ :note_date ] || dojo [ :created_at ]
143143 [ sort_date , dojo [ :order ] ]
144144 end
@@ -148,14 +148,14 @@ def activity
148148
149149 def parse_date_from_note ( date_match )
150150 return nil if date_match . nil?
151-
151+
152152 date_string = date_match . to_s
153-
153+
154154 # 日本語形式の日付を標準形式に変換(例: 2025年8月24日 → 2025-08-24)
155155 if date_string . include? ( '年' )
156156 date_string = date_string . gsub ( /(\d {4})年(\d {1,2})月(\d {1,2})日/ , '\1-\2-\3' )
157157 end
158-
158+
159159 Time . zone . parse ( date_string )
160160 rescue ArgumentError
161161 nil
0 commit comments