Class: KDE::Url
Class Method Summary collapse
- ._load(str) ⇒ Object
-
.file_url?(str, abs_only = false) ⇒ Boolean
Tells whether a string looks like an url pointing to a file.
- .yaml_new(cls, tag, val) ⇒ Object
Instance Method Summary collapse
- #_dump(_) ⇒ Object
-
#eql?(other) ⇒ Boolean
true if the two URLs are equal according to @==@ and false otherwise.
-
#hash ⇒ Integer
Override of Object#hash.
- #local_file? ⇒ Boolean
- #remote_file? ⇒ Boolean
- #to_yaml(opts = {}) ⇒ Object
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.
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 |
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.
81 82 83 |
# File 'lib/ruber/kde_sugar.rb', line 81 def eql? other self == other end |
#hash ⇒ Integer
Override of Object#hash
89 90 91 |
# File 'lib/ruber/kde_sugar.rb', line 89 def hash path.hash end |
#local_file? ⇒ Boolean
69 70 71 |
# File 'lib/ruber/kde_sugar.rb', line 69 def local_file? scheme == "file" end |
#remote_file? ⇒ 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 |