OtbJobQueue

Solution for the OTB Job Queue Challenge

Installation

Add this line to your application's Gemfile:

gem 'otb_job_queue'

And then execute:

$ bundle

Or install it yourself as:

$ gem install otb_job_queue

Usage

require "otb_job_queue"

# create a new job sequencer instance with a parser dependency
sequencer = OtbJobQueue::JobsSequencer.new(OtbJobQueue::JobsParser)

# job sequencing is invoked by calling .call method on the sequencer, with the appropriate input
sequencer.call("a => ") 
    #=> "a"
sequencer.call("a => b, b => ") 
    #=> "ba"
sequencer.call("a => , b => c, c => ")
    #=> "acb"
sequencer.call("a => ,b => c, c => f, d => a, e => b, f => ")
    #=> "afcbde"

# as long as the input format is (job) => (dependency), it will sequence the string
sequencer.call("a => \nb => c\nc => f\nd => a \ne => b\n f => ")
    #=> "afcbde"
sequencer.call("a =>  b => c c => f d => a e => b f => ")
    #=> "afcbde"

Error Handling

require "otb_job_queue"

sequencer = OtbJobQueue::JobsSequencer.new(OtbJobQueue::JobsParser)

# If the job => dependency list has a circular dependency, CircularDependencyError will be raised
sequencer.call("a => \nb => c\nc => f\nd => a \ne => \n f => b")
    #=> OtbJobQueue::JobsSequencer::CircularDependencyError (Jobs can't have circular dependencies: topological sort failed: ["b", "c", "f"])

# If the job => dependency list has a self dependency, SelfDependencyError will be raised
sequencer.call("a => , b => c, c => c")
    #=> OtbJobQueue::JobsSequencer::SelfDependencyError (Jobs can't depend on themselves: c => c)

# If the invalid input type or invalid string format is given, InputError will be raised
sequencer.call({})
    #=> OtbJobQueue::JobsParser::InputError ({:jobs_input=>["must be String", "must be empty or is in invalid format"]})
sequencer.call("a=>b=>cc=>c")
    #=> OtbJobQueue::JobsParser::InputError ({:jobs_input=>["must be empty or is in invalid format"]})

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitLab at https://gitlab.com/chanjman/otb-job-queue. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the OtbJobQueue project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.