Class: Percolate::Facet::HostnameFacet
- Defined in:
- lib/percolate/facet/hostname_facet.rb
Overview
A facet for looking up entities based on hostname.
Instance Attribute Summary collapse
-
#domains ⇒ Object
Returns the value of attribute domains.
-
#hostnames ⇒ Object
Returns the value of attribute hostnames.
-
#organizations ⇒ Object
Returns the value of attribute organizations.
Instance Method Summary collapse
- #find(hostname) ⇒ Object
-
#initialize ⇒ HostnameFacet
constructor
A new instance of HostnameFacet.
- #merge(other) ⇒ Object
Constructor Details
#initialize ⇒ HostnameFacet
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
#domains ⇒ Object
Returns the value of attribute domains.
23 24 25 |
# File 'lib/percolate/facet/hostname_facet.rb', line 23 def domains @domains end |
#hostnames ⇒ Object
Returns the value of attribute hostnames.
23 24 25 |
# File 'lib/percolate/facet/hostname_facet.rb', line 23 def hostnames @hostnames end |
#organizations ⇒ Object
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
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 |