Class: SecurityTxt::Parser
- Inherits:
-
Object
- Object
- SecurityTxt::Parser
- Defined in:
- lib/securitytxt/parser.rb
Overview
Parser of Security.txt
Instance Method Summary collapse
Instance Method Details
#parse(str) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/securitytxt/parser.rb', line 4 def parse(str) sections = {} str.each_line do |line| line.chomp! l = line.to_s.gsub(/#.*$/, '') next if l.index(': ').nil? section, value = l.split(': ', 2) key = section.to_s.downcase current = sections[key] case current when NilClass sections[key] = value when Array sections[key] << value.strip else sections[key] = [current, value] end end sections end |