class Path
class Path
lib/path.tya:2
Path provides the path/Path standard library API.
Source
# Path provides the path/Path standard library API.
class Path
# Path.value stores instance state.
# @type Nil
value: nil
# Path.basename returns the last path element.
# @param value String value value.
# @return String the resulting value.
static basename: value ->
Path(nil).basename(value)
# Path.clean normalizes dot segments and repeated separators.
# @param value String value value.
# @return Any the resulting value.
static clean: value ->
Path(nil).clean(value)
# Path.dirname returns all but the last path element.
# @param value String value value.
# @return String the resulting value.
static dirname: value ->
Path(nil).dirname(value)
# Path.expand_user expands a leading ~ using the current home directory.
# @param value String value value.
# @return Any the resulting value.
static expand_user: value ->
path_expand_user(value)
# Path.extname returns the extension of value.
# @param value String value value.
# @return String the resulting value.
static extname: value ->
Path(nil).extname(value)
# Path.join joins path parts and cleans the result.
# @param parts Array parts value.
# @return String the resulting value.
static join: parts ->
Path(nil).join(parts)
# Path.initialize stores a filesystem path.
# @param value String value value.
# @return Self the initialized object.
initialize: value = nil ->
self.value = value
# Path.basename provides the path/Path standard library operation.
# @param value String value value.
# @return String the resulting value.
basename: value = nil ->
if value == nil
value = self.value
parts = value.split("/")
i = parts.len() - 1
while i >= 0
if parts[i] != ""
return parts[i]
i = i - 1
""
# Path.clean provides the path/Path standard library operation.
# @param value String value value.
# @return Any the resulting value.
clean: value = nil ->
if value == nil
value = self.value
if value == ""
return "."
is_abs = value.starts_with("/")
parts = value.split("/")
result = []
for part in parts
if part != "" and part != "."
if part == ".."
n = result.len()
if n > 0 and result[n - 1] != ".."
result.pop()
elseif not is_abs
result.push("..")
else
result.push(part)
joined = result.join("/")
if is_abs
return "/" + joined
if joined == ""
return "."
joined
# Path.dirname provides the path/Path standard library operation.
# @param value String value value.
# @return String the resulting value.
dirname: value = nil ->
if value == nil
value = self.value
parts = value.split("/")
last = parts.len() - 1
while last >= 0 and parts[last] == ""
last = last - 1
if last <= 0
if value.starts_with("/")
return "/"
return "."
head = []
i = 0
while i < last
head.push(parts[i])
i = i + 1
joined = head.join("/")
if joined == ""
return "."
joined
# Path.expand_user provides the path/Path standard library operation.
# @param value String value value.
# @return Any the resulting value.
expand_user: value = nil ->
if value == nil
value = self.value
path_expand_user(value)
# Path.extname provides the path/Path standard library operation.
# @param value String value value.
# @return String the resulting value.
extname: value = nil ->
if value == nil
value = self.value
bparts = value.split("/")
bi = bparts.len() - 1
base = ""
while bi >= 0 and base == ""
if bparts[bi] != ""
base = bparts[bi]
bi = bi - 1
parts = base.split(".")
n = parts.len()
if n < 2
return ""
if parts[0] == "" and n == 2
return ""
"." + parts[n - 1]
# Path.join provides the path/Path standard library operation.
# @param parts Array parts value.
# @return String the resulting value.
join: parts = nil ->
if parts == nil
parts = self.value
raw = parts.join("/")
if raw == ""
return "."
is_abs = raw.starts_with("/")
sparts = raw.split("/")
result = []
for part in sparts
if part != "" and part != "."
if part == ".."
n = result.len()
if n > 0 and result[n - 1] != ".."
result.pop()
elseif not is_abs
result.push("..")
else
result.push(part)
joined = result.join("/")
if is_abs
return "/" + joined
if joined == ""
return "."
joined
Instance Variables
value
Path.value
lib/path.tya:5
Path.value stores instance state.
Source
# Path.value stores instance state.
# @type Nil
value: nil
Static Methods
basename
static Path.basename(value)
lib/path.tya:10
Path.basename returns the last path element.
Source
# Path.basename returns the last path element.
# @param value String value value.
# @return String the resulting value.
static basename: value ->
Path(nil).basename(value)
clean
static Path.clean(value)
lib/path.tya:16
Path.clean normalizes dot segments and repeated separators.
Source
# Path.clean normalizes dot segments and repeated separators.
# @param value String value value.
# @return Any the resulting value.
static clean: value ->
Path(nil).clean(value)
dirname
static Path.dirname(value)
lib/path.tya:22
Path.dirname returns all but the last path element.
Source
# Path.dirname returns all but the last path element.
# @param value String value value.
# @return String the resulting value.
static dirname: value ->
Path(nil).dirname(value)
expand_user
static Path.expand_user(value)
lib/path.tya:28
Path.expand_user expands a leading ~ using the current home directory.
Source
# Path.expand_user expands a leading ~ using the current home directory.
# @param value String value value.
# @return Any the resulting value.
static expand_user: value ->
path_expand_user(value)
extname
static Path.extname(value)
lib/path.tya:34
Path.extname returns the extension of value.
Source
# Path.extname returns the extension of value.
# @param value String value value.
# @return String the resulting value.
static extname: value ->
Path(nil).extname(value)
join
static Path.join(parts)
lib/path.tya:40
Path.join joins path parts and cleans the result.
Source
# Path.join joins path parts and cleans the result.
# @param parts Array parts value.
# @return String the resulting value.
static join: parts ->
Path(nil).join(parts)
Methods
basename
Path.basename(value = nil)
lib/path.tya:52
Path.basename provides the path/Path standard library operation.
Source
# Path.basename provides the path/Path standard library operation.
# @param value String value value.
# @return String the resulting value.
basename: value = nil ->
if value == nil
value = self.value
parts = value.split("/")
i = parts.len() - 1
while i >= 0
if parts[i] != ""
return parts[i]
i = i - 1
""
clean
Path.clean(value = nil)
lib/path.tya:66
Path.clean provides the path/Path standard library operation.
Source
# Path.clean provides the path/Path standard library operation.
# @param value String value value.
# @return Any the resulting value.
clean: value = nil ->
if value == nil
value = self.value
if value == ""
return "."
is_abs = value.starts_with("/")
parts = value.split("/")
result = []
for part in parts
if part != "" and part != "."
if part == ".."
n = result.len()
if n > 0 and result[n - 1] != ".."
result.pop()
elseif not is_abs
result.push("..")
else
result.push(part)
joined = result.join("/")
if is_abs
return "/" + joined
if joined == ""
return "."
joined
dirname
Path.dirname(value = nil)
lib/path.tya:94
Path.dirname provides the path/Path standard library operation.
Source
# Path.dirname provides the path/Path standard library operation.
# @param value String value value.
# @return String the resulting value.
dirname: value = nil ->
if value == nil
value = self.value
parts = value.split("/")
last = parts.len() - 1
while last >= 0 and parts[last] == ""
last = last - 1
if last <= 0
if value.starts_with("/")
return "/"
return "."
head = []
i = 0
while i < last
head.push(parts[i])
i = i + 1
joined = head.join("/")
if joined == ""
return "."
joined
expand_user
Path.expand_user(value = nil)
lib/path.tya:118
Path.expand_user provides the path/Path standard library operation.
Source
# Path.expand_user provides the path/Path standard library operation.
# @param value String value value.
# @return Any the resulting value.
expand_user: value = nil ->
if value == nil
value = self.value
path_expand_user(value)
extname
Path.extname(value = nil)
lib/path.tya:126
Path.extname provides the path/Path standard library operation.
Source
# Path.extname provides the path/Path standard library operation.
# @param value String value value.
# @return String the resulting value.
extname: value = nil ->
if value == nil
value = self.value
bparts = value.split("/")
bi = bparts.len() - 1
base = ""
while bi >= 0 and base == ""
if bparts[bi] != ""
base = bparts[bi]
bi = bi - 1
parts = base.split(".")
n = parts.len()
if n < 2
return ""
if parts[0] == "" and n == 2
return ""
"." + parts[n - 1]
initialize
Path.initialize(value = nil)
lib/path.tya:46
Path.initialize stores a filesystem path.
Source
# Path.initialize stores a filesystem path.
# @param value String value value.
# @return Self the initialized object.
initialize: value = nil ->
self.value = value
join
Path.join(parts = nil)
lib/path.tya:147
Path.join provides the path/Path standard library operation.
Source
# Path.join provides the path/Path standard library operation.
# @param parts Array parts value.
# @return String the resulting value.
join: parts = nil ->
if parts == nil
parts = self.value
raw = parts.join("/")
if raw == ""
return "."
is_abs = raw.starts_with("/")
sparts = raw.split("/")
result = []
for part in sparts
if part != "" and part != "."
if part == ".."
n = result.len()
if n > 0 and result[n - 1] != ".."
result.pop()
elseif not is_abs
result.push("..")
else
result.push(part)
joined = result.join("/")
if is_abs
return "/" + joined
if joined == ""
return "."
joined