Class: Percolate::Facet::HostnameFacet

Inherits:
BaseFacet
  • Object
show all
Defined in:
lib/percolate/facet/hostname_facet.rb

Overview

A facet for looking up entities based on hostname.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHostnameFacet

Returns a new instance of HostnameFacet.



25
26
27
28
29
# File 'lib/percolate/facet/hostname_facet.rb', line 25

def initialize
  @hostnames = {}
  @domains = {}
  @organizations = {}
end

Instance Attribute Details

#domainsObject

Returns the value of attribute domains.



23
24
25
# File 'lib/percolate/facet/hostname_facet.rb', line 23

def domains
  @domains
end

#hostnamesObject

Returns the value of attribute hostnames.



23
24
25
# File 'lib/percolate/facet/hostname_facet.rb', line 23

def hostnames
  @hostnames
end

#organizationsObject

Returns the value of attribute organizations.



23
24
25
# File 'lib/percolate/facet/hostname_facet.rb', line 23

def organizations
  @organizations
end

Instance Method Details

#find(hostname) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/percolate/facet/hostname_facet.rb', line 31

def find(hostname)
  return @hostnames[hostname] if @hostnames.include?(hostname)

  comps = hostname.split(".", -1)
  domain = comps[1...3].join(".")

  return @domains[domain] if @domains.include?(domain)

  organization = comps[1]

  @organizations.fetch(organization, organization)
end

#merge(other) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
# File 'lib/percolate/facet/hostname_facet.rb', line 44

def merge(other)
  raise ArgumentError, "Please provide another #{self.class}" if !other.is_a?(HostnameFacet)

  merged = HostnameFacet.new
  merged.hostnames = @hostnames.merge(other.hostnames)
  merged.domains = @domains.merge(other.domains)
  merged.organizations = @organizations.merge(other.organizations)

  merged
end