class OtbJobQueue::JobsParser
Parses a string of jobs into an hash
Constants
- JOBS_QUEUE_FORMAT
- Schema
JobsParser's Validation schema Successful validation if input is an empty String or a String of valid format
Public Class Methods
call(jobs_input)
click to toggle source
Creates a new JobsParser
instance and calls the .call method on it @api public @return [JobsParser.new(jobs_input).call, InputError] the jobs hash @example
OtbJobQueue::JobsParser.call('a => \nb => \nc => b') => { "a"=> [], "b"=> [], "c" => ["b"] } OtbJobQueue::JobsParser.call('Hello World!') => InputError ({ :jobs_input => ["must be empty or is in invalid format"] })
# File lib/otb_job_queue/jobs_parser.rb, line 34 def self.call(jobs_input) validation = self::Schema.call(jobs_input: jobs_input) if validation.success? new(jobs_input).call else raise InputError, validation.messages end end
new(jobs_input)
click to toggle source
Creates a new instance of the JobsParser
with the valid jobs_input param @param jobs_input [String] jobs string
# File lib/otb_job_queue/jobs_parser.rb, line 16 def initialize(jobs_input) @jobs_input = jobs_input end
Public Instance Methods
call()
click to toggle source
# File lib/otb_job_queue/jobs_parser.rb, line 43 def call parse end
Private Instance Methods
parse()
click to toggle source
Parses a string of jobs into an hash @api private @return [Hash] the jobs hash
# File lib/otb_job_queue/jobs_parser.rb, line 52 def parse @jobs_input.scan(JOBS_QUEUE_FORMAT).each_with_object({}) do |(job, dependency), memo| memo[job] = dependency.empty? ? [] : [dependency] end end