Class: UniformResourceIdentifier::Relative
- Inherits:
-
Object
- Object
- UniformResourceIdentifier::Relative
- Extended by:
- Parsable
- Defined in:
- lib/uniform_resource_identifier/relative.rb
Instance Attribute Summary collapse
-
#anchor ⇒ Object
Returns the value of attribute anchor.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#directory ⇒ Object
# = Delegates = # ======================================================================= #.
- #directory=(directory) ⇒ Object
- #file ⇒ Object
- #file=(file) ⇒ Object
-
#initialize(relative = nil) ⇒ Relative
constructor
A new instance of Relative.
-
#path ⇒ Object
# = Attributes = # ======================================================================= #.
- #path=(path) ⇒ Object
- #query ⇒ Object
- #query=(query) ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Methods included from Parsable
Constructor Details
#initialize(relative = nil) ⇒ Relative
Returns a new instance of Relative.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/uniform_resource_identifier/relative.rb', line 12 def initialize(relative=nil) if relative.respond_to?(:to_str) parsed_uri = Parser.parse(relative) # TODO elsif relative.respond_to?(:to_hash) relative = relative.to_hash.symbolize_keys @path = Path.parse(relative[:path]) if relative.has_key?(:path) @query = Query.parse(relative[:query]) if relative.has_key?(:query) @anchor = relative[:anchor].to_s.gsub(/^#/, '') if relative.has_key?(:anchor) else raise(TypeError, "relative must either be a String or a Hash") unless relative.nil? end end |
Instance Attribute Details
#anchor ⇒ Object
Returns the value of attribute anchor.
67 68 69 |
# File 'lib/uniform_resource_identifier/relative.rb', line 67 def anchor @anchor end |
Instance Method Details
#blank? ⇒ Boolean
43 44 45 |
# File 'lib/uniform_resource_identifier/relative.rb', line 43 def blank? @path.blank? && @query.blank? && @anchor.blank? end |
#directory ⇒ Object
#
Delegates = #
#
77 78 79 |
# File 'lib/uniform_resource_identifier/relative.rb', line 77 def directory self.path.directory end |
#directory=(directory) ⇒ Object
81 82 83 |
# File 'lib/uniform_resource_identifier/relative.rb', line 81 def directory=(directory) self.path.directory = directory end |
#file ⇒ Object
85 86 87 |
# File 'lib/uniform_resource_identifier/relative.rb', line 85 def file self.path.file end |
#file=(file) ⇒ Object
89 90 91 |
# File 'lib/uniform_resource_identifier/relative.rb', line 89 def file=(file) self.path.file = file end |
#path ⇒ Object
#
Attributes = #
#
51 52 53 |
# File 'lib/uniform_resource_identifier/relative.rb', line 51 def path @path ||= Path.new end |
#path=(path) ⇒ Object
55 56 57 |
# File 'lib/uniform_resource_identifier/relative.rb', line 55 def path=(path) @path = Path.parse(path) end |
#query ⇒ Object
59 60 61 |
# File 'lib/uniform_resource_identifier/relative.rb', line 59 def query @query ||= Query.new end |
#query=(query) ⇒ Object
63 64 65 |
# File 'lib/uniform_resource_identifier/relative.rb', line 63 def query=(query) @query = Query.parse(query) end |
#to_h ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/uniform_resource_identifier/relative.rb', line 35 def to_h { :path => path.nil? ? nil : @path.to_h, :query => query.nil? ? nil : @query.to_h, :anchor => @anchor } end |
#to_s ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/uniform_resource_identifier/relative.rb', line 27 def to_s query = "/#{@path}" if @path.blank? || !@path.to_s[/^\//] query = "?#{@query}" unless @query.blank? anchor = "##{@anchor}" unless @anchor.blank? "#{path}#{query}#{anchor}" end |