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

._load(str) ⇒ Object



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

def self._load str
  self.new str
end

.file_url?(str, abs_only = false) ⇒ Boolean

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

.yaml_new(cls, tag, val) ⇒ Object



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

#_dump(_) ⇒ Object



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

def _dump _
  to_encoded.to_s
end

#eql?(other) ⇒ Boolean

Returns 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

#hashInteger

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

#local_file?Boolean

Returns:

  • (Boolean)


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

def local_file?
  scheme == "file"
end

#remote_file?Boolean

Returns:

  • (Boolean)


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

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

#to_yaml(opts = {}) ⇒ Object



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