Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rcap/extensions/string.rb

Constant Summary

CAP_LIST_REGEX =
Regexp.new( '"([\w\s]+)"|(\S+)' )
WHITESPACE_REGEX =
Regexp.new('^\s+$')

Instance Method Summary (collapse)

Instance Method Details

- (String) for_cap_list

Reformats string for a CAP list. If the string contains whitespace it will enclose the contents in quotation marks.

Examples:

"one".for_cap_list       # => "one"
"two words".for_cap_list # => "\"two words\""

Returns:



12
13
14
15
16
17
18
# File 'lib/rcap/extensions/string.rb', line 12

def for_cap_list
  if self =~ /\s/
    '"'+self+'"'
  else
    self
  end
end

- (Array<String>) unpack_cap_list

Will unpack a string generated by Array#to_s_for_cap

Examples:

"one \"two words\" three".unpack_cap_list # => [ "one", "two words", "three" ]

Returns:

See Also:



26
27
28
# File 'lib/rcap/extensions/string.rb', line 26

def unpack_cap_list
  self.split( CAP_LIST_REGEX ).reject{ |match| match == "" || match =~ WHITESPACE_REGEX }
end