fjord/main.rb

31 lines
543 B
Ruby
Raw Normal View History

2024-03-24 22:20:46 +09:00
class Gate
2024-03-25 22:14:46 +09:00
STATIONS = [:umeda, :juso, :mikuni]
FARES = [160, 190]
2024-03-24 22:20:46 +09:00
def initialize(name)
@name = name
end
def enter(ticket)
2024-03-25 22:14:46 +09:00
ticket.stamp(@name)
2024-03-24 22:20:46 +09:00
end
def exit(ticket)
2024-03-25 22:14:46 +09:00
fare = calc_fare(ticket)
fare <= ticket.fare
end
def calc_fare(ticket)
from = STATIONS.index(ticket.stamped_at)
to = STATIONS.index(@name)
distance = to - from
FARES[distance - 1]
2024-03-24 22:20:46 +09:00
end
end
class Ticket
2024-03-25 22:14:46 +09:00
attr_reader :fare, :stamped_at
2024-03-24 22:20:46 +09:00
def initialize(fare)
@fare = fare
2024-03-23 22:59:51 +09:00
end
2024-03-25 22:14:46 +09:00
def stamp(name)
@stamped_at = name
end
2024-03-16 22:40:05 +09:00
end