Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/dredd/rack/runner.rb

Instance Method Summary collapse

Instance Method Details

#has_at_least_one_argument?Boolean

Verify that a command has at least one argument (excluding options)

Examples:

"dredd doc/*.apib".valid? # => true
"dredd doc/*.apib doc/*apib.md".valid? # => true
"dredd doc/*.apib --level verbose".valid? # => true
"dredd".valid? # => false
"dredd --dry-run".valid? # => false
"dredd --dry-run --level verbose".valid? # => false

Known limitations:

Does not support short flags. (e.g. using ‘-l` instead of `–level`). Requires options to be specified after the last argument.

Note:

The known limitations imply that there may be false negatives: this method can return false for commands that do have two arguments or more. But there should not be false positives: if the method returns true, then the command does have at least two arguments.

Returns true if the command String has at least one arguments, false otherwise.

Returns:

  • (Boolean)


183
184
185
# File 'lib/dredd/rack/runner.rb', line 183

def has_at_least_one_argument?
  split('--').first.split(' ').length >= 2
end

#has_at_least_two_arguments?Boolean

Verify that a command has at least two arguments (excluding options)

Examples:

"dredd doc/*.apib http://api.example.com".valid? # => true
"dredd doc/*.apib doc/*apib.md http://api.example.com".valid? # => true
"dredd doc/*.apib http://api.example.com --level verbose".valid? # => true
"dredd http://api.example.com".valid? # => false
"dredd doc/*.apib --dry-run".valid? # => false
"dredd --dry-run --level verbose".valid? # => false

Known limitations:

Does not support short flags. (e.g. using ‘-l` instead of `–level`). Requires options to be specified after the last argument.

Note:

The known limitations imply that there may be false negatives: this method can return false for commands that do have two arguments or more. But there should not be false positives: if the method returns true, then the command does have at least two arguments.

Returns true if the command String has at least two arguments, false otherwise.

Returns:

  • (Boolean)


211
212
213
# File 'lib/dredd/rack/runner.rb', line 211

def has_at_least_two_arguments?
  split('--').first.split(' ').length >= 3
end

#quote!Object

Include quotes as part of the string

Examples:

"Hello, world!".quote! # => "\"Hello, world!\""
"Hello, world!".size # => 13
"Hello, world!".quote!.size # => 15

Returns a String, whose first and last characters are quotes.



224
225
226
# File 'lib/dredd/rack/runner.rb', line 224

def quote!
  '"' + self + '"'
end