// Generated by CoffeeScript 1.8.0
(function() {
  var partition, rpartition;

  partition = function(str, delimiter) {
    var s;
    s = str.split(delimiter);
    return [s[0], delimiter, s[1]];
  };

  rpartition = function(str, delimiter) {
    var s;
    s = str.split(delimiter).reverse();
    return [s[1], delimiter, s[0]];
  };

  String.prototype.to_uri = function() {
    this.render = function() {
      var s;
      s = '';
      if (this.scheme) {
        s += this.scheme + '://';
      }
      if (this.namespace) {
        s += this.namespace + '@';
      }
      s += this.path;
      if (this.ext) {
        s += '.' + this.ext;
      }
      if (this.version) {
        s += '#' + this.version;
      }
      return s;
    };
    this.valueOf = function() {
      return this.render();
    };
    this.from_parts = function(obj) {
      this.scheme = obj.scheme;
      this.namespace = obj.namespace;
      this.path = obj.path;
      this.ext = obj.ext;
      this.version = obj.version;
      return this.parts = {
        scheme: this.scheme,
        namespace: this.namespace,
        path: this.path,
        ext: this.ext,
        version: this.version
      };
    };
    this.parse = function(uri_str) {
      var base, ext, namespace, path, scheme, version, _, _ref, _ref1, _ref2, _ref3;
      _ref = partition(uri_str, '#'), base = _ref[0], _ = _ref[1], version = _ref[2];
      _ref1 = rpartition(base, '://'), scheme = _ref1[0], _ = _ref1[1], path = _ref1[2];
      _ref2 = rpartition(path, '@'), namespace = _ref2[0], _ = _ref2[1], path = _ref2[2];
      _ref3 = partition(path, '.'), path = _ref3[0], _ = _ref3[1], ext = _ref3[2];
      return {
        scheme: scheme || null,
        namespace: namespace || null,
        path: path,
        ext: ext || null,
        version: version || null
      };
    };
    this.from_str = function(uri_str) {
      return this.from_parts(this.parse(uri_str));
    };
    this.clone = function(obj) {
      return this.from_parts(_.extend(obj, this.parts));
    };
    this.from_parts(this.parse(this));
    return this;
  };

}).call(this);
