Class: UniformResourceIdentifier::Path
- Inherits:
-
Object
- Object
- UniformResourceIdentifier::Path
- Extended by:
- Parsable
- Defined in:
- lib/uniform_resource_identifier/path.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
# = Attributes = # ======================================================================= #.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(path = nil) ⇒ Path
constructor
A new instance of Path.
- #to_h ⇒ Object
- #to_s ⇒ Object
Methods included from Parsable
Constructor Details
#initialize(path = nil) ⇒ Path
Returns a new instance of Path.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/uniform_resource_identifier/path.rb', line 9 def initialize(path=nil) if path.respond_to?(:to_str) parsed_uri = Parser.parse(path) @directory, @file = parsed_uri.values_at(:directory, :file) elsif path.respond_to?(:to_hash) path.to_hash.symbolize_keys @directory, @file = path.values_at(:directory, :file) else raise(TypeError, "path must either be a String or a Hash") unless path.nil? end end |
Instance Attribute Details
#directory ⇒ Object
#
Attributes = #
#
39 40 41 |
# File 'lib/uniform_resource_identifier/path.rb', line 39 def directory @directory end |
#file ⇒ Object
Returns the value of attribute file.
40 41 42 |
# File 'lib/uniform_resource_identifier/path.rb', line 40 def file @file end |
Instance Method Details
#blank? ⇒ Boolean
32 33 34 |
# File 'lib/uniform_resource_identifier/path.rb', line 32 def blank? @directory.blank? && @file.blank? end |
#to_h ⇒ Object
25 26 27 28 29 30 |
# File 'lib/uniform_resource_identifier/path.rb', line 25 def to_h { :directory => @directory, :file => @file } end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/uniform_resource_identifier/path.rb', line 21 def to_s "#{@directory}#{@file}" end |