class MethodStruct::ArgumentParser

Attributes

options[R]

Public Class Methods

new(options) click to toggle source
# File lib/method_struct/argument_parser.rb, line 3
def initialize(options)
  @options = options
end

Public Instance Methods

call() click to toggle source
# File lib/method_struct/argument_parser.rb, line 7
def call
  parsed_arguments.tap do |args|
    ArgumentVerifier.new(options.merge(:arguments => args)).call
  end
end

Private Instance Methods

fields() click to toggle source
# File lib/method_struct/argument_parser.rb, line 16
def fields
  options.fetch(:fields)
end
parsed_arguments() click to toggle source
# File lib/method_struct/argument_parser.rb, line 24
def parsed_arguments
  {}.tap do |h|
    fields.each do |field|
      h[field] = raw_arguments_hash[field] if raw_arguments_hash.key?(field)
    end
  end
end
raw_arguments() click to toggle source
# File lib/method_struct/argument_parser.rb, line 20
def raw_arguments
  options.fetch(:raw_arguments)
end
raw_arguments_hash() click to toggle source
# File lib/method_struct/argument_parser.rb, line 32
def raw_arguments_hash
  @raw_arguments_hash ||= if fields.size > 1 && raw_arguments.size == 1 && raw_arguments.first.is_a?(Hash)
    raw_arguments.first
  else
    zipped_fields = fields.take(raw_arguments.count)
    Hash[*zipped_fields.zip(raw_arguments).flatten(1)]
  end
end