Class: String

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/rcap/extensions/string.rb', line 30

def blank?
  empty?
end

#for_cap_listString

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

#unpack_cap_listArray<String>

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
  split(CAP_LIST_REGEX).reject { |match| match == '' || match =~ WHITESPACE_REGEX }
end