Class: TokyoMetro::Static::RailwayLine::Hash

Inherits:
Fundamental::Hash show all
Includes:
ClassNameLibrary::Static::RailwayLine, Modules::Common::ToFactory::Seed::Hash
Defined in:
lib/tokyo_metro/static/railway_line/hash.rb

Overview

複数の路線の情報を扱うクラス(ハッシュ)

Instance Method Summary collapse

Methods included from Modules::Common::ToFactory::Seed::Group

#seed

Methods included from Modules::Static::Hash::DefineTest

#define_test

Instance Method Details

#select_main_color(str) ⇒ ::TokyoMetro::Static::Color

与えられた路線名の文字列から色を取得するメソッド

Parameters:

  • str (String)

    路線名の文字列

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tokyo_metro/static/railway_line/hash.rb', line 10

def select_main_color( str )
  if self.keys.include?( str )
    return self[ str ].color.first
  else
    #---- 末尾が数字の場合 ここから
    if /\A(odpt\.Railway\:[a-zA-Z\-\.]+)\.(\d+?)\Z/ =~ str
      str , num = $1 , $2.to_i
      # 文字列部分が self の key である場合
      if self.keys.include?( str )
        color_info = self[ str ].color
        if color_info.instance_of?( ::Array ) and num <= color_info.length
          return color_info[ num - 1 ]
        end
      end
    end
    #---- 末尾が数字の場合 ここまで
  end
  puts self.keys
  puts ""
  raise "Error: \"#{str}\" is not valid."
end