Class: UniformResourceIdentifier::Path

Inherits:
Object
  • Object
show all
Extended by:
Parsable
Defined in:
lib/uniform_resource_identifier/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parsable

parse

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

#directoryObject

#

Attributes = #

#


39
40
41
# File 'lib/uniform_resource_identifier/path.rb', line 39

def directory
  @directory
end

#fileObject

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/uniform_resource_identifier/path.rb', line 32

def blank?
  @directory.blank? && @file.blank?
end

#to_hObject



25
26
27
28
29
30
# File 'lib/uniform_resource_identifier/path.rb', line 25

def to_h
  {
    :directory => @directory,
    :file => @file
  }
end

#to_sObject



21
22
23
# File 'lib/uniform_resource_identifier/path.rb', line 21

def to_s
  "#{@directory}#{@file}"
end