Module: Nanoc3::StringExtensions
- Included in:
- String
- Defined in:
- lib/nanoc3/base/core_ext/string.rb
Instance Method Summary collapse
-
#checksum ⇒ String
private
Calculates the checksum for this string.
-
#cleaned_identifier ⇒ String
Transforms string into an actual identifier.
-
#make_compatible_with_env ⇒ String
Replaces Unicode characters with their ASCII decompositions if the environment does not support Unicode.
Instance Method Details
#checksum ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Calculates the checksum for this string. Any change to this string will result in a different checksum.
36 37 38 39 40 |
# File 'lib/nanoc3/base/core_ext/string.rb', line 36 def checksum digest = Digest::SHA1.new digest.update(self) digest.hexdigest end |
#cleaned_identifier ⇒ String
Transforms string into an actual identifier
8 9 10 |
# File 'lib/nanoc3/base/core_ext/string.rb', line 8 def cleaned_identifier "/#{self}/".gsub(/^\/+|\/+$/, '/') end |
#make_compatible_with_env ⇒ String
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.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nanoc3/base/core_ext/string.rb', line 19 def make_compatible_with_env # Check whether environment supports Unicode # FIXME this is ugly, and there most likely are better ways to do this is_unicode_supported = %w( LC_ALL LC_CTYPE LANG ).any? { |e| ENV[e] =~ /UTF/ } return self if is_unicode_supported # Decompose if necessary # FIXME this decomposition is not generally usable self.gsub(/“|”/, '"').gsub(/‘|’/, '\'').gsub('…', '...') end |