Class: Path::URI

Inherits:
Path show all
Defined in:
lib/epitools/path.rb

Overview

A wrapper for URI objects.

Constant Summary

Constants inherited from Path

AUTOGENERATED_CLASS_METHODS, BINARY_EXTENSION, COMPRESSORS, PATH_SEPARATOR, URI_RE

Instance Attribute Summary collapse

Attributes inherited from Path

#base, #dirs, #ext

Instance Method Summary collapse

Methods inherited from Path

#/, #<=>, #==, #=~, [], #[], #[]=, #append, #atime, #atime=, #attrs, #attrs=, #backup!, #backup_file, #broken_symlink?, cd, #cd, #child_of?, #chmod, #chmod_R, #chown, #chown_R, #cp, #cp_p, #cp_r, #ctime, #deflate, #dir, #dir=, #dir?, #each_chunk, #each_line, #endswith, escape, #executable?, #exists?, expand_path, #exts, #file?, #filename, #filename=, getfattr, glob, #grep, #gunzip!, #gzip!, #hash, #hidden?, home, #id3, #inflate, #initialize_copy, ln_s, #ln_s, #ls, ls, #ls_R, #ls_dirs, #ls_files, #ls_r, ls_r, #lstat, #magic, #md5, #mimetype, #mimetype_from_ext, #mkcd, mkcd, #mode, #mtime, #mtime=, #mv, #mv!, #name, new, #numbered_backup!, #numbered_backup_file, #owner?, #parent, #parent_of?, #parse, #parse_lines, #path, #path=, popd, pushd, #puts, pwd, #read_bson, #read_csv, #read_html, #read_json, #read_marshal, #read_xml, #read_yaml, #readable?, #realpath, #relative, #relative?, #relative_to, #reload!, #rename, #rename!, #reset!, #rm, setfattr, #sha1, #sha2, #sha256, #siblings, #size, #sort_attrs, #startswith, #symlink?, #symlink_target, #symlink_to, tmpdir, tmpfile, #to_Path, #touch, #truncate, #type, #unmarshal, #update, #url?, which, #writable?, #write, #write_bson, #write_json, #write_marshal, #write_yaml, #zopen

Methods included from Enumerable

#*, #**, #average, #blank?, #combination, #counts, #cross_product, #foldl, #group_neighbours_by, #grouped_to_h, #groups, #map_recursively, #parallel_map, #permutation, #powerset, #reverse, #reverse_each, #rle, #rzip, #select_recursively, #skip, #sort_numerically, #split_after, #split_at, #split_before, #split_between, #sum, #to_iter, #uniq, #unzip

Methods included from Array::ToCSV

#to_csv, #to_tsv

Constructor Details

#initialize(uri, hints = {}) ⇒ URI

TODO: only include certain methods from Path (delegate style)

(eg: remove commands that write)

1636
1637
1638
1639
# File 'lib/epitools/path.rb', line 1636

def initialize(uri, hints={})
  @uri = ::URI.parse(uri)
  self.path = @uri.path
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.


1630
1631
1632
# File 'lib/epitools/path.rb', line 1630

def uri
  @uri
end

Instance Method Details

#hostObject

…and this is: 'host.com'


1677
# File 'lib/epitools/path.rb', line 1677

def host; uri.host; end

#http?Boolean

`http?` checks for 'http' OR 'https' schemes

Returns:

  • (Boolean)

1670
1671
1672
# File 'lib/epitools/path.rb', line 1670

def http?
  super or https?
end

#inspectObject


1654
1655
1656
# File 'lib/epitools/path.rb', line 1654

def inspect
  "#<Path::URI:#{to_s}>"
end

#join(other) ⇒ Object


1695
1696
1697
# File 'lib/epitools/path.rb', line 1695

def join(other)
  Path.new URI.join(path, other).to_s
end

#open(mode = "r", &block) ⇒ Object Also known as: io

…and `path` is /path/filename.ext


1702
1703
1704
1705
1706
1707
1708
1709
# File 'lib/epitools/path.rb', line 1702

def open(mode="r", &block)
  require 'open-uri'
  if block_given?
    ::URI.open(to_s, mode, &block)
  else
    ::URI.open(to_s, mode)
  end
end

#portObject

…and this is: 80


1682
# File 'lib/epitools/path.rb', line 1682

def port; uri.port; end

#queryObject

…and this is: {param1: value1, param2: value2, …etc… }


1687
1688
1689
1690
1691
1692
1693
# File 'lib/epitools/path.rb', line 1687

def query
  if query = uri.query
    query.to_params
  else
    nil
  end
end

#read(*args) ⇒ Object


1713
1714
1715
# File 'lib/epitools/path.rb', line 1713

def read(*args)
  open { |io| io.read(*args) }
end

#schemeObject Also known as: protocol


1658
1659
1660
# File 'lib/epitools/path.rb', line 1658

def scheme
  uri.scheme
end

#to_pathObject


1651
# File 'lib/epitools/path.rb', line 1651

def to_path; to_s; end

#to_sObject


1650
# File 'lib/epitools/path.rb', line 1650

def to_s; uri.to_s; end

#to_strObject


1652
# File 'lib/epitools/path.rb', line 1652

def to_str; to_s; end

#uri?Boolean

Returns:

  • (Boolean)

1641
1642
1643
# File 'lib/epitools/path.rb', line 1641

def uri?
  true
end