Class: Lotus::Utils::PathPrefix
- Defined in:
- lib/lotus/utils/path_prefix.rb
Overview
Prefixed string
Constant Summary collapse
- DEFAULT_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Path separator
'/'.freeze
Constants inherited from String
String::CAPITALIZE_SEPARATOR, String::CLASSIFY_SEPARATOR, String::CLASSIFY_WORD_SEPARATOR, String::DASHERIZE_SEPARATOR, String::EMPTY_STRING, String::NAMESPACE_SEPARATOR, String::TITLEIZE_SEPARATOR, String::TOKENIZE_REGEXP, String::TOKENIZE_SEPARATOR, String::UNDERSCORE_DIVISION_TARGET, String::UNDERSCORE_SEPARATOR
Instance Method Summary collapse
-
#initialize(string = nil, separator = DEFAULT_SEPARATOR) ⇒ PathPrefix
constructor
Initialize the path prefix.
-
#join(*strings) ⇒ Lotus::Utils::PathPrefix
Joins self with the given token.
-
#relative_join(strings, separator = @separator) ⇒ Lotus::Utils::PathPrefix
Joins self with the given token, without prefixing it with ‘separator`.
Methods inherited from String
#==, #capitalize, #classify, #dasherize, #demodulize, #gsub, #hash, #method_missing, #namespace, #pluralize, #respond_to_missing?, #rsub, #scan, #singularize, #split, #titleize, #to_s, #tokenize, #underscore
Constructor Details
#initialize(string = nil, separator = DEFAULT_SEPARATOR) ⇒ PathPrefix
Initialize the path prefix
26 27 28 29 |
# File 'lib/lotus/utils/path_prefix.rb', line 26 def initialize(string = nil, separator = DEFAULT_SEPARATOR) super(string) @separator = separator end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Lotus::Utils::String
Instance Method Details
#join(*strings) ⇒ Lotus::Utils::PathPrefix
Joins self with the given token. It cleans up all the ‘separator` repetitions.
57 58 59 |
# File 'lib/lotus/utils/path_prefix.rb', line 57 def join(*strings) relative_join(strings).absolute! end |
#relative_join(strings, separator = @separator) ⇒ Lotus::Utils::PathPrefix
Joins self with the given token, without prefixing it with ‘separator`. It cleans up all the `separator` repetitions.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/lotus/utils/path_prefix.rb', line 80 def relative_join(strings, separator = @separator) raise TypeError if separator.nil? prefix = @string.gsub(@separator, separator) result = [prefix, strings] result.flatten! result.compact! result.reject! {|string| string == separator } self.class.new( result.join(separator), separator ).relative! end |