Class: Site

Inherits:
Object
  • Object
show all
Defined in:
lib/domain/site/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, description:, risk_score:, scan_engine:, scan_template:) ⇒ Site

Returns a new instance of Site.



6
7
8
9
10
11
12
13
# File 'lib/domain/site/model.rb', line 6

def initialize(id:, name:, description:, risk_score:, scan_engine:, scan_template:)
  @id = id
  @name = name
  @description = description
  @risk_score = risk_score
  @scan_engine = scan_engine
  @scan_template = scan_template
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/domain/site/model.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/domain/site/model.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/domain/site/model.rb', line 4

def name
  @name
end

#risk_scoreObject

Returns the value of attribute risk_score.



4
5
6
# File 'lib/domain/site/model.rb', line 4

def risk_score
  @risk_score
end

#scan_engineObject

Returns the value of attribute scan_engine.



4
5
6
# File 'lib/domain/site/model.rb', line 4

def scan_engine
  @scan_engine
end

#scan_templateObject

Returns the value of attribute scan_template.



4
5
6
# File 'lib/domain/site/model.rb', line 4

def scan_template
  @scan_template
end

Class Method Details

.from_json(data) ⇒ Object

data json comes from the API sites/get



16
17
18
19
20
21
22
23
24
25
# File 'lib/domain/site/model.rb', line 16

def self.from_json(data)
  Site.new(
    id: data['id'],
    name: data['name'],
    description: data['description'],
    risk_score: data['risk_score'],
    scan_engine: data['scanEngine'],
    scan_template: data['scanTemplate']
  )
end

Instance Method Details

#country_codeObject



49
50
51
52
53
54
# File 'lib/domain/site/model.rb', line 49

def country_code
  return nil unless utr?

  matches = name.match(/^:(.*?):/)
  matches ? matches[1] : nil
end

#scan_template_idObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/domain/site/model.rb', line 31

def scan_template_id
  return nil unless utr?

  if name.include?(':za:')
    # settings[:za_full_audit]
    '_-sa-ca-_100_-_-pps_min-2000-_-max-15000-_--_-full-audit-without-web-spider'
  else
    # settings[:ar_full_audit]
    '_-angola-ca-_100_-_-pps_min-450-_-max-450-_--_-full-audit-without-web-spider-copy'
  end
end

#time_zone(country_code) ⇒ Object

returns the time_zone from the 2-letter country code



45
46
47
# File 'lib/domain/site/model.rb', line 45

def time_zone(country_code)
  # {'a'}
end

#to_sObject



27
28
29
# File 'lib/domain/site/model.rb', line 27

def to_s
  [id, name, scan_engine, scan_template].join ','
end

#utr?Boolean

returns true if the site ends with _UTR followed by 5 digits

Returns:

  • (Boolean)


63
64
65
66
67
68
69
# File 'lib/domain/site/model.rb', line 63

def utr?
  # Define the regular expression pattern
  utr_pattern = /:UTR\d{5}$/

  # Check if the site ends with "_UTR" followed by one or more digits
  !!(name =~ utr_pattern)
end

#utr_digitsObject



56
57
58
59
60
# File 'lib/domain/site/model.rb', line 56

def utr_digits
  utr_pattern = /:UTR(\d{5})$/
  digits = name.match(utr_pattern)
  digits ? digits[1].to_i : 0
end