Class: TokyoMetro::Api::StationTimetable::Info::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/tokyo_metro/api/station_timetable/info/hash.rb

Overview

個別の列車の情報の配列を値とするハッシュ

Instance Method Summary collapse

Instance Method Details

#to_sString

ハッシュの情報を文字列として取得するメソッド

Returns:

  • (String)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tokyo_metro/api/station_timetable/info/hash.rb', line 6

def to_s
  str_ary = ::Array.new
  self.each do | day , timetable |
    str_ary << day
    str_ary << ""
    timetable.each do | train |
      str_ary << ( " " * 2 + train.to_s )
    end
    str_ary << ""
  end
  str_ary.join( "\n" )
end

#to_strf(indent = 0) ⇒ String

インスタンスの情報を整形した文字列にして返すメソッド

Parameters:

  • indent (Integer (>=0) (defaults to: 0)

    ] インデントの幅

Returns:

  • (String)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tokyo_metro/api/station_timetable/info/hash.rb', line 22

def to_strf( indent = 0 )
  str_ary = ::Array.new
  self.each do | key , value |
    str_ary_for_each_timetable = ::Array.new
    str_ary_for_each_timetable << key
    str_ary_for_each_timetable << ""
    str_ary_for_each_timetable << value.to_strf(2)
    str_ary << " " * indent + str_ary_for_each_timetable.join( "\n" )
  end

  str_ary.map { | str | " " * indent }.join( "\n" * 3 )
end