Class: SecurityTxt::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/securitytxt/generator.rb

Overview

Generator of Security.txt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Generator

Returns a new instance of Generator.



5
6
7
# File 'lib/securitytxt/generator.rb', line 5

def initialize(data = {})
  @sections = data
end

Instance Attribute Details

#sectionsObject

Returns the value of attribute sections.



4
5
6
# File 'lib/securitytxt/generator.rb', line 4

def sections
  @sections
end

Instance Method Details

#generateObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/securitytxt/generator.rb', line 9

def generate
  ret = StringIO.new
  sections.each do |name, value|
    next if value.nil? || value.empty?
    if value.is_a?(Array)
      value.each { |subvalue| ret << "#{capitalize(name)}: #{subvalue}\n" }
    else
      ret << "#{capitalize(name)}: #{value}\n"
    end
  end
  ret.string
end