Sha256: 8e9c0de2b1a747d00488fa35f85b83064d54f17369575510ae667f175875b475

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

module Coprl
  # Provides a query interface for the ruby parameters method
  class Parameters
    def initialize(parameters)
      @params = parameters
    end

    def args
      @params.select {|p| p.first == :req || p.first == :opt}
    end

    def required_args
      @params.select {|p| p.first == :req}
    end

    def required_args?
      required_args.any?
    end

    def optional_args
      @params.select {|p| p.first == :opt}
    end

    def optional_args?
      optional_args.any?
        end

    def splats_args
      @params.select {|p| p.first == :rest}
    end

    def splats_args?
      splats_args.any?
    end
    
    def options
      @params.select {|p| p.first == :keyreq || p.first == :key}
    end

    def options?
      options.any?
    end

    def required_options
      @params.select {|p| p.first == :keyreq}
    end

    def required_options?
      required_options.any?
    end
    

    def optional_options
      @params.select {|p| p.first == :key}
    end

    def optional_options?
      optional_options.any?
    end

    def spalts_options
      @params.select {|p| p.first == :keyrest}
    end

    def splats_options?
      spalts_options.any?
    end

    def names(args_or_options)
      args_or_options.map(&:last)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 lib/coprl/parameters.rb
coprl-3.0.0.beta.11 lib/coprl/parameters.rb
coprl-3.0.0.beta.10 lib/coprl/parameters.rb
coprl-3.0.0.beta.9 lib/coprl/parameters.rb
coprl-3.0.0.beta.8 lib/coprl/parameters.rb
coprl-3.0.0.beta.7 lib/coprl/parameters.rb
coprl-3.0.0.beta.6 lib/coprl/parameters.rb
coprl-3.0.0.beta.5 lib/coprl/parameters.rb
coprl-3.0.0.beta.4 lib/coprl/parameters.rb
coprl-3.0.0.beta.3 lib/coprl/parameters.rb
coprl-3.0.0.beta.2 lib/coprl/parameters.rb
coprl-3.0.0.beta.1 lib/coprl/parameters.rb