Class: Util::PrepareData
Instance Attribute Summary collapse
-
#transformed_data ⇒ Object
readonly
Returns the value of attribute transformed_data.
Instance Method Summary collapse
- #add_cis ⇒ Object
- #convert_str(value) ⇒ Object
-
#initialize(clean_text) ⇒ PrepareData
constructor
A new instance of PrepareData.
- #parse(clean_text) ⇒ Object
Constructor Details
#initialize(clean_text) ⇒ PrepareData
Returns a new instance of PrepareData.
333 334 335 336 337 338 339 340 341 |
# File 'lib/utilities/parser.rb', line 333 def initialize(clean_text) @parser = ControlParser.new @attributes = [] data = parse(clean_text) @transformed_data = Trans.new.apply(data) add_cis end |
Instance Attribute Details
#transformed_data ⇒ Object (readonly)
Returns the value of attribute transformed_data.
343 344 345 |
# File 'lib/utilities/parser.rb', line 343 def transformed_data @transformed_data end |
Instance Method Details
#add_cis ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/utilities/parser.rb', line 355 def add_cis @transformed_data&.map do |ctrl| if !ctrl[:cis] && ctrl[:ref] references = ctrl[:ref].split("\n") references.each do |ref| match = ref.scan(/(?<=#)\d+\.\d+/).map(&:inspect).join(',').delete('"').tr(',', ' ') ctrl[:cis] = match.split unless match.empty? end ctrl[:cis] = 'No CIS Control' unless ctrl[:cis] elsif !ctrl[:cis] && !ctrl[:ref] ctrl[:cis] = 'No CIS Control' elsif ctrl[:cis] && ctrl[:ref] ctrl[:cis] = ctrl[:cis].scan(/^\d+[.\d+]*/) end end end |
#convert_str(value) ⇒ Object
351 352 353 |
# File 'lib/utilities/parser.rb', line 351 def convert_str(value) value.to_s end |
#parse(clean_text) ⇒ Object
345 346 347 348 349 |
# File 'lib/utilities/parser.rb', line 345 def parse(clean_text) @parser.parse(clean_text) rescue Parslet::ParseFailed => e puts e.parse_failure_cause.ascii_tree end |