Module: Valise::Unpath

Included in:
Item, PathMatcher, SearchRoot, Set, Set::Definer, Set::StemmedDefiner, Stack
Defined in:
lib/valise/utils.rb

Instance Method Summary collapse

Instance Method Details

#repath(segments) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/valise/utils.rb', line 55

def repath(segments)
  case segments
  when Array
    return segments.join(::File::Separator)
  when String
    return segments
  end
end

#unpath(parts) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/valise/utils.rb', line 21

def unpath(parts)
  if Array === parts and parts.length == 1
    parts = parts[0]
  end

  case parts
  when Array
    if (parts.find{|part| not (String === part or Symbol === part)}.nil?)
      parts = parts.map{|part| part.to_s}
    else
      raise ArgumentError, "path must be composed of strings or symbols"
    end
  when String
    parts = parts.split(::File::Separator)
  when Symbol
    parts = [parts.to_s]
  when ::File
    parts = parts.path
    parts = parts.split(::File::Separator)
  else
    raise ArgumentError, "path must be String, Array of Strings or File"
  end

  parts = parts.map do |part|
    if /^~/ =~ part
      ::File::expand_path(part).split(::File::Separator)
    else
      part
    end
  end.flatten

  return parts
end