Class: String

Inherits:
Object show all
Includes:
Spec::Expectations::StringHelpers
Defined in:
lib/gems/builder-2.1.2/lib/builder/xchar.rb,
lib/gems/genosaurus-1.2.4/lib/genosaurus.rb,
lib/gems/logging-0.9.4/lib/logging/utils.rb,
lib/gems/rspec-1.1.11/lib/spec/story/extensions/string.rb,
lib/gems/rspec-1.1.11/lib/spec/expectations/extensions/string_and_symbol.rb

Overview

Enhance the String class with a XML escaped character version of to_s.

Instance Method Summary collapse

Methods included from Spec::Expectations::StringHelpers

#starts_with?

Instance Method Details

#arg_regexpObject



6
7
8
# File 'lib/gems/rspec-1.1.11/lib/spec/story/extensions/string.rb', line 6

def arg_regexp
  ::Spec::Story::Step::PARAM_OR_GROUP_PATTERN
end

#reduce(width, ellipses = '...') ⇒ Object

call-seq:

reduce( width, ellipses = '...' )    #=> string

Reduce the size of the current string to the given width by removing characters from the middle of the string and replacing them with ellipses. If the width is greater than the length of the string, the string is returned unchanged. If the width is less than the length of the ellipses, then the ellipses are returned.

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gems/logging-0.9.4/lib/logging/utils.rb', line 54

def reduce( width, ellipses = '...')
  raise ArgumentError, "width cannot be negative: #{width}" if width < 0

  return self if length <= width

  remove = length - width + ellipses.length
  return ellipses.dup if remove >= length

  left_end = (length + 1 - remove) / 2
  right_start = left_end + remove

  left = self[0,left_end]
  right = self[right_start,length-right_start]

  left << ellipses << right
end

#step_nameObject



2
3
4
# File 'lib/gems/rspec-1.1.11/lib/spec/story/extensions/string.rb', line 2

def step_name
  self
end

#to_xsObject

XML escaped version of to_s



110
111
112
113
114
# File 'lib/gems/builder-2.1.2/lib/builder/xchar.rb', line 110

def to_xs
  unpack('U*').map {|n| n.xchr}.join # ASCII, UTF-8
rescue
  unpack('C*').map {|n| n.xchr}.join # ISO-8859-1, WIN-1252
end

#underscoreObject



8
9
10
11
12
13
14
15
# File 'lib/gems/genosaurus-1.2.4/lib/genosaurus.rb', line 8

def underscore
  camel_cased_word = self.dup
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end