Class: TokyoMetro::Api::Point::Info::Title::Code

Inherits:
Object
  • Object
show all
Defined in:
lib/tokyo_metro/api/point/info/title/code.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, additional_info_ja) ⇒ Code

Returns a new instance of Code.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Attribute Details

#additional_info_jaObject (readonly)

Returns the value of attribute additional_info_ja.



33
34
35
# File 'lib/tokyo_metro/api/point/info/title/code.rb', line 33

def additional_info_ja
  @additional_info_ja
end

#another_infoObject (readonly)

Returns the value of attribute another_info.



32
33
34
# File 'lib/tokyo_metro/api/point/info/title/code.rb', line 32

def another_info
  @another_info
end

#first_charObject (readonly)

Returns the value of attribute first_char.



29
30
31
# File 'lib/tokyo_metro/api/point/info/title/code.rb', line 29

def first_char
  @first_char
end

#last_charObject (readonly)

Returns the value of attribute last_char.



31
32
33
# File 'lib/tokyo_metro/api/point/info/title/code.rb', line 31

def last_char
  @last_char
end

#numberObject (readonly)

Returns the value of attribute number.



30
31
32
# File 'lib/tokyo_metro/api/point/info/title/code.rb', line 30

def number
  @number
end

Instance Method Details

#<=>(other) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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