Module: DTRCore::Common

Included in:
Function, InstructionValidator, Parser, State, TypeValidator, UserDefinedType
Defined in:
lib/dtr_core/common.rb

Overview

Common methods used by the DTRCore module.

Instance Method Summary collapse

Instance Method Details

#capture_section(pattern) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/dtr_core/common.rb', line 10

def capture_section(pattern)
  captures = content.match(pattern)&.captures

  if content.scan(pattern).length > 1
    raise 'Multiple captures found for a section.'
  elsif captures
    captures&.first
  end
end

#clean_name(definition) ⇒ Object



20
21
22
# File 'lib/dtr_core/common.rb', line 20

def clean_name(definition)
  definition.gsub(/[\*\n\[]/, '').strip
end

#split_strip_select(some_list) ⇒ Object



6
7
8
# File 'lib/dtr_core/common.rb', line 6

def split_strip_select(some_list)
  some_list&.split("\n")&.map(&:strip)&.select { |x| x.length.positive? }
end