class TokyoMetro::Api::Point::Info::Title::Code

Attributes

additional_info_ja[R]
another_info[R]
first_char[R]
last_char[R]
number[R]

Public Class Methods

new( code , additional_info_ja ) click to toggle source
# File lib/tokyo_metro/api/point/info/title/code.rb, line 3
def initialize( code , additional_info_ja )
  @first_char = nil
  @number = nil
  @last_char = nil
  @another_info = nil
  @additional_info_ja = nil

  if code.string?
    if /\A([A-Z]?)(\d{1,2})([a-z]?)/ =~ code
      @first_char = $1
      @number = $2.to_i
      @last_char = $3
    else
      @another_info = code
    end
  else
    unless code.nil?
      raise "Error: TokyoMetro::Api::Point::Info::Title::Code - #{ code } is not valid."
    end
  end

  if additional_info_ja.present?
    @additional_info_ja = additional_info_ja
  end
end

Public Instance Methods

<=>( other ) click to toggle source
# File lib/tokyo_metro/api/point/info/title/code.rb, line 35
def <=>( other )
  #-------- first_char が異なる場合
  c_first_char = compare_by( other , :first_char )
  if c_first_char.present?
    return c_first_char
  end

  #-------- first_char が同じで number が異なる場合
  c_number = compare_by( other , :number )
  if c_number.present?
    return c_number
  end

  #-------- first_char, number が同じで last_char が異なる場合
  c_last_char = compare_by( other , :last_char )
  if c_last_char.present?
    return c_last_char
  end

  c_another_info = compare_by( other , :another_info )
  if c_another_info.present?
    return c_another_info
  end

  c_additional_info_ja = compare_by( other , :additional_info_ja )
  if c_additional_info_ja.present?
    return c_additional_info_ja
  end

  return 0
end

Private Instance Methods

compare_by( other , method_name ) click to toggle source
# File lib/tokyo_metro/api/point/info/title/code.rb, line 69
def compare_by( other , method_name )
  if send( method_name ).blank? and other.send( method_name ).present?
    return -1
  elsif send( method_name ).present? and other.send( method_name ).present?
    unless send( method_name ) == other.send( method_name )
      return ( send( method_name ) <=> other.send( method_name ) )
    end
  elsif send( method_name ).present? and other.send( method_name ).blank?
    return 1
  else
    nil
  end
end