Class: Stylesheet::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/stylesheet/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, parent = nil) ⇒ Location

Returns a new instance of Location.



9
10
11
12
13
14
15
16
# File 'lib/stylesheet/location.rb', line 9

def initialize(url, parent = nil)      
  @uri    = parse_uri(url)
  @host   = uri.host
  @parent = parent

  self.init_from_uri
  self.expand_paths_from_parent
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



4
5
6
# File 'lib/stylesheet/location.rb', line 4

def hash
  @hash
end

#hostObject Also known as: hostname

Returns the value of attribute host.



3
4
5
# File 'lib/stylesheet/location.rb', line 3

def host
  @host
end

#hrefObject Also known as: to_s

Returns the value of attribute href.



3
4
5
# File 'lib/stylesheet/location.rb', line 3

def href
  @href
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/stylesheet/location.rb', line 4

def parent
  @parent
end

#pathnameObject

Returns the value of attribute pathname.



4
5
6
# File 'lib/stylesheet/location.rb', line 4

def pathname
  @pathname
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/stylesheet/location.rb', line 4

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



4
5
6
# File 'lib/stylesheet/location.rb', line 4

def protocol
  @protocol
end

#searchObject

Returns the value of attribute search.



4
5
6
# File 'lib/stylesheet/location.rb', line 4

def search
  @search
end

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/stylesheet/location.rb', line 3

def uri
  @uri
end

Instance Method Details

#expand_paths_from_parentObject



53
54
55
56
57
58
59
60
# File 'lib/stylesheet/location.rb', line 53

def expand_paths_from_parent
  return if valid_protocol?
  return unless parent

  self.pathname = URI.join(parent.to_s, uri.path).path
  self.protocol = parent.protocol
  self.host     = parent.host
end

#init_from_uriObject



18
19
20
21
22
23
24
# File 'lib/stylesheet/location.rb', line 18

def init_from_uri
  self.protocol = uri.scheme
  self.pathname = uri.path
  self.port     = uri.port
  self.search   = uri.query
  self.hash     = uri.fragment
end

#valid?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/stylesheet/location.rb', line 49

def valid?
  !!(valid_protocol? && valid_host?)
end