Class: KDE::Url

Inherits:
Object show all
Defined in:
lib/ruber/kde_sugar.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) _load(str)



65
66
67
# File 'lib/ruber/kde_sugar.rb', line 65

def self._load str
  self.new str
end

+ (Boolean) file_url?(str, abs_only = false)

Tells whether a string looks like an url pointing to a file

An url is considered to look like an url pointing to a file if it contains a scheme part and an authority part, that is, if it starts with a scheme followed by two slashes.

If abs_only is true, this method returns true only if the file path is absolute, that is if the scheme is followed by three slashes. If abs_only is false, it’ll return true for both absolute and relative paths.

Parameters:

  • str (String)

    the string to test

  • abs_only (Boolean) (defaults to: false)

    whether this method should return true only if the path is absolute or also for relative paths

Returns:

  • (Boolean)

    true if str looks like an URL pointing to a file (or pointing to an absolute file if abs_only is true) and false otherwise



50
51
52
53
# File 'lib/ruber/kde_sugar.rb', line 50

def self.file_url? str, abs_only = false
  slash_number = abs_only ? 3 : 2
  str.match(%r|[\w+.-]+:/{#{slash_number},3}|).to_b
end

+ (Object) yaml_new(cls, tag, val)



30
31
32
# File 'lib/ruber/kde_sugar.rb', line 30

def self.yaml_new cls, tag, val
  KDE::Url.new val
end

Instance Method Details

- (Object) _dump(_)



61
62
63
# File 'lib/ruber/kde_sugar.rb', line 61

def _dump _
  to_encoded.to_s
end

- (Boolean) eql?(other)

true if the two URLs are equal according to == and false otherwise

Returns:

  • (Boolean)

    true if the two URLs are equal according to == and false otherwise



81
82
83
# File 'lib/ruber/kde_sugar.rb', line 81

def eql? other
  self == other
end

- (Integer) hash

Override of Object#hash

Returns:

  • (Integer)

    the hash value of the path associated with the URL



89
90
91
# File 'lib/ruber/kde_sugar.rb', line 89

def hash
  path.hash
end

- (Boolean) local_file?

Returns:

  • (Boolean)


69
70
71
# File 'lib/ruber/kde_sugar.rb', line 69

def local_file?
  scheme == "file"
end

- (Boolean) remote_file?

Returns:

  • (Boolean)


73
74
75
# File 'lib/ruber/kde_sugar.rb', line 73

def remote_file?
  !(local_file? or relative?)
end

- (Object) to_yaml(opts = {})



55
56
57
58
59
# File 'lib/ruber/kde_sugar.rb', line 55

def to_yaml opts = {}
  YAML.quick_emit(self, opts) do |out|
    out.scalar taguri, to_encoded.to_s, :plain
  end
end