Skip to content

soniillusions/train

Repository files navigation

Train Management Ruby Program

Description

This is a console-based Train Management Application where I practiced Object-Oriented Programming (OOP) principles, exception handling, and metaprogramming.

Features

  • Object-Oriented design with encapsulation, inheritance, and polymorphism.
  • Exception handling for better error management.
  • Metaprogramming techniques to dynamically define methods and enhance flexibility.
  • Custom validation system with DSL for data validation (presence, format, type checks).
  • Interactive terminal menu using tty-prompt.

The application allows users to:

  • Create and manage trains, routes, and stations.
  • Assign routes to trains and control train movement.
  • View and modify train details through an interactive menu.

Installation

Install required Ruby gems with Bundler:

bundle install

Running the Application

To start the application, run:

ruby main.rb

Custom Validation System

The project includes a custom validation module that provides a DSL for data validation:

class ExampleClass
  include Validation
  
  validate :attribute, :presence           # Checks that attribute is not nil/empty
  validate :number, :format, /\d{3}-\d{2}/ # Validates format with regex
  validate :object, :type, String          # Validates object type
  
  def initialize
    validate!  # Raises ValidationError on failure
  end
  
  def valid?
    validate!  # Returns true/false, prints errors
  rescue ValidationError
    false
  end
end

The validation system uses metaprogramming to dynamically call appropriate validators and supports inheritance for custom validation logic in subclasses.

About

A Ruby program for managing trains and stations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages