Module: FuzzyURL::URLComponents

Included in:
FuzzyURL
Defined in:
lib/fuzzy_url/url_components.rb

Overview

FuzzyURL::URLComponents provides getting/setting of URL components on FuzzyURL objects in hash style (e.g. ‘foo`) and method style (e.g. `foo.hostname`). Acceptable URL components are :protocol, :username, :password, :hostname, :port, :path, :query, and :fragment.

Constant Summary collapse

COMPONENTS =
[:protocol, :username, :password, :hostname,
:port, :path, :query, :fragment]

Instance Method Summary collapse

Instance Method Details

#[](component) ⇒ Object

Gets a URL component.



14
15
16
17
18
19
20
21
# File 'lib/fuzzy_url/url_components.rb', line 14

def [](component)
  component_sym = component.to_sym
  if !COMPONENTS.include?(component_sym)
    raise ArgumentError, "#{component.inspect} is not a URL component. "+
                         COMPONENTS.inspect
  end
  @components[component_sym]
end

#[]=(component, value) ⇒ Object

Sets a URL component.



24
25
26
27
28
29
30
31
# File 'lib/fuzzy_url/url_components.rb', line 24

def []=(component, value)
  component_sym = component.to_sym
  if !COMPONENTS.include?(component_sym)
    raise ArgumentError, "#{component.inspect} is not a URL component. "+
                         COMPONENTS.inspect
  end
  @components[component_sym] = value
end

#fragmentObject

Get the fragment for this FuzzyURL.



84
# File 'lib/fuzzy_url/url_components.rb', line 84

def fragment; self[:fragment] end

#fragment=(v) ⇒ Object

Set the fragment for this FuzzyURL.



87
# File 'lib/fuzzy_url/url_components.rb', line 87

def fragment=(v); self[:fragment]=v end

#hostnameObject

Get the hostname for this FuzzyURL.



56
# File 'lib/fuzzy_url/url_components.rb', line 56

def hostname; self[:hostname] end

#hostname=(v) ⇒ Object

Set the hostname for this FuzzyURL.



59
# File 'lib/fuzzy_url/url_components.rb', line 59

def hostname=(v); self[:hostname]=v end

#passwordObject

Get the password for this FuzzyURL.



49
# File 'lib/fuzzy_url/url_components.rb', line 49

def password; self[:password] end

#password=(v) ⇒ Object

Set the password for this FuzzyURL.



52
# File 'lib/fuzzy_url/url_components.rb', line 52

def password=(v); self[:password]=v end

#pathObject

Get the path for this FuzzyURL.



70
# File 'lib/fuzzy_url/url_components.rb', line 70

def path; self[:path] end

#path=(v) ⇒ Object

Set the path for this FuzzyURL.



73
# File 'lib/fuzzy_url/url_components.rb', line 73

def path=(v); self[:path]=v end

#portObject

Get the port for this FuzzyURL.



63
# File 'lib/fuzzy_url/url_components.rb', line 63

def port; self[:port] end

#port=(v) ⇒ Object

Set the port for this FuzzyURL.



66
# File 'lib/fuzzy_url/url_components.rb', line 66

def port=(v); self[:port]=v end

#protocolObject

Get the protocol for this FuzzyURL.



35
# File 'lib/fuzzy_url/url_components.rb', line 35

def protocol; self[:protocol] end

#protocol=(v) ⇒ Object

Set the protocol for this FuzzyURL.



38
# File 'lib/fuzzy_url/url_components.rb', line 38

def protocol=(v); self[:protocol]=v end

#queryObject

Get the query for this FuzzyURL.



77
# File 'lib/fuzzy_url/url_components.rb', line 77

def query; self[:query] end

#query=(v) ⇒ Object

Set the query for this FuzzyURL.



80
# File 'lib/fuzzy_url/url_components.rb', line 80

def query=(v); self[:query]=v end

#usernameObject

Get the username for this FuzzyURL.



42
# File 'lib/fuzzy_url/url_components.rb', line 42

def username; self[:username] end

#username=(v) ⇒ Object

Set the username for this FuzzyURL.



45
# File 'lib/fuzzy_url/url_components.rb', line 45

def username=(v); self[:username]=v end