class Stylesheet::Location
Attributes
hash[R]
host[RW]
hostname[RW]
hostname=[RW]
href[RW]
parent[R]
pathname[R]
port[R]
protocol[R]
search[R]
to_s[RW]
uri[RW]
Public Class Methods
new(url, parent = nil)
click to toggle source
# 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
Public Instance Methods
expand_paths_from_parent()
click to toggle source
# 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
hash=(hash)
click to toggle source
# File lib/stylesheet/location.rb, line 44 def hash=(hash) hash = hash.to_s.gsub("#", "") @hash = hash && hash != "" ? "##{hash}" : "" end
init_from_uri()
click to toggle source
# 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
pathname=(pathname)
click to toggle source
# File lib/stylesheet/location.rb, line 31 def pathname=(pathname) @pathname = pathname && pathname[0,1] == "/" ? pathname : "/#{pathname}" end
port=(port)
click to toggle source
# File lib/stylesheet/location.rb, line 35 def port=(port) @port = standard_port? ? "" : "#{port}" end
protocol=(protocol)
click to toggle source
# File lib/stylesheet/location.rb, line 26 def protocol=(protocol) protocol = protocol.to_s.gsub(":", "") @protocol = "#{protocol}:" end
search=(search)
click to toggle source
# File lib/stylesheet/location.rb, line 39 def search=(search) search = search.to_s.gsub("?", "") @search = search && search != "" ? "?#{search}" : "" end
valid?()
click to toggle source
# File lib/stylesheet/location.rb, line 49 def valid? !!(valid_protocol? && valid_host?) end
Private Instance Methods
parse_uri(url)
click to toggle source
# File lib/stylesheet/location.rb, line 98 def parse_uri(url) uri = begin URI.parse(url.strip) rescue URI::InvalidURIError URI.parse(URI.escape(url.strip)) end # re-raise external library errors in our namespace rescue URI::InvalidURIError => error raise Stylesheet::InvalidLocationError.new( "#{error.class}: #{error.message}") end
port_443?()
click to toggle source
# File lib/stylesheet/location.rb, line 94 def port_443? uri && uri.port == 443 && uri.scheme == "https" end
port_80?()
click to toggle source
# File lib/stylesheet/location.rb, line 90 def port_80? uri && uri.port == 80 && uri.scheme == "http" end
standard_port?()
click to toggle source
# File lib/stylesheet/location.rb, line 86 def standard_port? port_80? || port_443? end
valid_host?()
click to toggle source
# File lib/stylesheet/location.rb, line 78 def valid_host? host && host != "" end
valid_port?()
click to toggle source
# File lib/stylesheet/location.rb, line 82 def valid_port? port && port != "" end
valid_protocol?()
click to toggle source
# File lib/stylesheet/location.rb, line 74 def valid_protocol? protocol && protocol != ":" end