Class: Baron::TrainType

Inherits:
Object
  • Object
show all
Defined in:
lib/baron/train_type.rb

Overview

A type of train available for use in the game

A TrainType will list the major attributes of the train, such as how many stations it is able to count, how much it costs, and when it becomes obsolete.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major_station_allowance, face_value, minor_station_allowance: nil, rusted_by: nil) ⇒ TrainType

Create a train type

this train may count this train may count train

Examples:

Baron::TrainType.new(
  2,
  Baron::Money.new(250),
  minor_station_allowance: 1,
  rusted_by: rusting_train_type
)

Parameters:

  • major_station_allowance (Fixnum)

    The number of major stations tha

  • face_value (Baron::Money)

    The amount this train costs

  • minor_station_allowance (Fixnum) (defaults to: nil)

    The number of minor stations that

  • rusted_by (Baron::TrainType) (defaults to: nil)

    The type of train that rusts this


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/baron/train_type.rb', line 69

def initialize(
  major_station_allowance,
  face_value,
  minor_station_allowance: nil,
  rusted_by: nil
)
  @major_station_allowance = major_station_allowance
  @minor_station_allowance = minor_station_allowance
  @face_value = face_value
  @rusted_by = rusted_by
end

Instance Attribute Details

#face_valueBaron::Money (readonly)

The face value cost of this train

Examples:

train_type.face_value

Returns:


37
38
39
# File 'lib/baron/train_type.rb', line 37

def face_value
  @face_value
end

#major_station_allowanceFixnum (readonly)

The number of major stations the train can count

The major station allowance can also be used towards minor stations provided that the train runs within the restrictions of the rules.

Examples:

train_type.major_station_allowance

Returns:

  • (Fixnum)

19
20
21
# File 'lib/baron/train_type.rb', line 19

def major_station_allowance
  @major_station_allowance
end

#minor_station_allowanceFixnum (readonly)

The number of minor stations the train can count

Examples:

train_type.minor_station_allowance

Returns:

  • (Fixnum)

28
29
30
# File 'lib/baron/train_type.rb', line 28

def minor_station_allowance
  @minor_station_allowance
end

#rusted_byBaron::TrainType (readonly)

The type of train which rusts this train

Once the first train of the type listed is sold, this train is rusted and becomes obsolete. Under most rules, it can no longer be run.

Examples:

train_type.rusted_by

Returns:


49
50
51
# File 'lib/baron/train_type.rb', line 49

def rusted_by
  @rusted_by
end

Instance Method Details

#to_sString

Return a string representation of this object

The format of a train which has a minor station allowance will be `major+minorT` such as “2+1T”

The format of a train which does not have a minor station allowance will be `majorT` such as “2T”

Examples:

train_type.to_s #=> '2+1T'

Returns:

  • (String)

    A string representation of the object


94
95
96
97
98
# File 'lib/baron/train_type.rb', line 94

def to_s
  result = major_station_allowance.to_s
  result += '+' + minor_station_allowance.to_s if minor_station_allowance
  result + 'T'
end