Class: CountryDiscoverySite

Inherits:
Domain::Model show all
Defined in:
lib/domain/site/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Domain::Model

columns, from_csv, from_json, headers, primary_key, #to_csv, #to_hash, #to_s, view

Constructor Details

#initialize(attributes = {}) ⇒ CountryDiscoverySite

Returns a new instance of CountryDiscoverySite.



166
167
168
169
170
# File 'lib/domain/site/model.rb', line 166

def initialize(attributes = {})
  attributes[:country] ||= self.class.country(attributes[:name]) if attributes[:name]
  attributes[:network_zone] ||= self.class.network_zone(attributes[:name]) if attributes[:name]
  super(attributes)
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



155
156
157
# File 'lib/domain/site/model.rb', line 155

def country
  @country
end

#idObject

Returns the value of attribute id.



155
156
157
# File 'lib/domain/site/model.rb', line 155

def id
  @id
end

#nameObject

Returns the value of attribute name.



155
156
157
# File 'lib/domain/site/model.rb', line 155

def name
  @name
end

#network_zoneObject

Returns the value of attribute network_zone.



155
156
157
# File 'lib/domain/site/model.rb', line 155

def network_zone
  @network_zone
end

#scan_engineObject

Returns the value of attribute scan_engine.



155
156
157
# File 'lib/domain/site/model.rb', line 155

def scan_engine
  @scan_engine
end

#scan_templateObject

Returns the value of attribute scan_template.



155
156
157
# File 'lib/domain/site/model.rb', line 155

def scan_template
  @scan_template
end

Class Method Details

.country(site_name) ⇒ Object

Extract the country between the start of the site name end the first occurence of the words [DMZ,Core,Data Centre]



182
183
184
185
186
187
188
189
190
# File 'lib/domain/site/model.rb', line 182

def self.country(site_name)
  network_zone_pattern = /DMZ|Core|Data Centre/
  parts = site_name.split(network_zone_pattern)
  if parts.length > 1
    parts.first.strip
  else
    'Unknown'
  end
end

.network_zone(site_name) ⇒ Object



172
173
174
175
176
177
178
# File 'lib/domain/site/model.rb', line 172

def self.network_zone(site_name)
  if site_name.include?('DMZ')
    'dmz'
  else
    'core'
  end
end

.table_nameObject



162
163
164
# File 'lib/domain/site/model.rb', line 162

def self.table_name
  'country_discovery_site'
end