Sha256: 2d1e88868d3c3bf788a5c33e4b29ef1c849024ffd89af979c39af100f2ea38f2

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

class String

  # Does the string end with the specified +suffix+ (stolen from
  # <tt>ActiveSupport::CoreExtensions::String::StartsEndsWith</tt>)?
  def ends_with?(suffix)
    suffix = suffix.to_s
    self[-suffix.length, suffix.length] == suffix
  end

  # Does the string start with the specified +prefix+ (stolen from
  # <tt>ActiveSupport::CoreExtensions::String::StartsEndsWith</tt>)?
  def starts_with?(prefix)
    prefix = prefix.to_s
    self[0, prefix.length] == prefix
  end

  # # Downcases a string and replaces spaces with underscores.  This
  # # works slightly differently than
  # # <tt>ActiveSupport::CoreExtensions::String::Inflections.underscore</tt>
  # # which is intended to be used for camel-cased Ruby constants.
  # #
  # #   "A long and unwieldy phrase".underscore #=> "a_long_and_unwieldy_phrase"
  # def underscore
  #   self.to_s.tr("-", "_").tr(" ","_").downcase
  # end

  # Returns the handle corresponding to this string as a symbol:
  #
  #   "A possible title of a dataset".handle #=> :a_possible_title_of_a_dataset
  def to_handle
    self.downcase.underscore.to_sym
  end

  # Dump this string into the given +uri+.
  def dump uri
    IMW.open!(uri).dump(self)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
imw-0.2.7 lib/imw/utils/extensions/string.rb
imw-0.2.6 lib/imw/utils/extensions/string.rb
imw-0.2.5 lib/imw/utils/extensions/string.rb
imw-0.2.4 lib/imw/utils/extensions/string.rb
imw-0.2.3 lib/imw/utils/extensions/string.rb
imw-0.2.2 lib/imw/utils/extensions/string.rb