Class/Module Index [+]

Quicksearch

Nanoc3::StringExtensions

Public Instance Methods

cleaned_identifier() click to toggle source

Transforms string into an actual identifier

@return [String] The identifier generated from the receiver

# File lib/nanoc3/base/core_ext/string.rb, line 7
def cleaned_identifier
  "/#{self}/".gsub(/^\/+|\/+$/, '/')
end
make_compatible_with_env() click to toggle source

Replaces Unicode characters with their ASCII decompositions if the environment does not support Unicode.

This method is not suited for general usage. If you need similar functionality, consider using the Iconv library instead.

@return [String] The decomposed string

# File lib/nanoc3/base/core_ext/string.rb, line 18
def make_compatible_with_env
  # Check whether environment supports Unicode
  # TODO this is ugly, and there most likely are better ways to do this
  is_unicode_supported = %( LC_ALL LC_CTYPE LANG ).any? { |e| ENV[e] =~ /UTF/ }
  return self if is_unicode_supported

  # Decompose if necessary
  # TODO this decomposition is not generally usable
  self.gsub(/“|”/, '"').gsub(/‘|’/, '\').gsub('…', '...')
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.