Module: Legion::Extensions::Rfp::Ingest::Runners::Parser

Extended by:
Helpers::Client
Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/rfp/ingest/runners/parser.rb

Instance Method Summary collapse

Methods included from Helpers::Client

client

Instance Method Details

#extract_requirements(text:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/legion/extensions/rfp/ingest/runners/parser.rb', line 33

def extract_requirements(text:, **)
  requirements = []

  text.each_line do |line|
    stripped = line.strip
    next if stripped.empty?

    if stripped.match?(/\b(?:must|shall|required|mandatory)\b/i)
      requirements << { text: stripped, type: :mandatory }
    elsif stripped.match?(/\b(?:should|preferred|desired|optional)\b/i)
      requirements << { text: stripped, type: :preferred }
    end
  end

  { result: requirements, mandatory: requirements.count { |r| r[:type] == :mandatory },
    preferred: requirements.count { |r| r[:type] == :preferred } }
end

#extract_sections(text:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/legion/extensions/rfp/ingest/runners/parser.rb', line 51

def extract_sections(text:, **)
  sections = []
  current_title = nil
  current_content = []

  text.each_line do |line|
    stripped = line.strip
    if stripped.match?(/\A(?:#{section_heading_pattern})/)
      sections << { title: current_title, content: current_content.join("\n").strip } if current_title
      current_title = stripped
      current_content = []
    else
      current_content << line
    end
  end

  sections << { title: current_title, content: current_content.join("\n").strip } if current_title
  { result: sections, count: sections.length }
end

#parse_rfp_questions(text:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/extensions/rfp/ingest/runners/parser.rb', line 11

def parse_rfp_questions(text:, **)
  questions = []
  current_section = nil

  text.each_line do |line|
    stripped = line.strip
    next if stripped.empty?

    if stripped.match?(/\A(?:section|part|category)\s+/i) || stripped.match?(/\A[A-Z][A-Z\s]{2,}[A-Z]\z/)
      current_section = stripped
    elsif stripped.match?(/\A\d+[.)]\s/) || stripped.match?(/\A[a-z][.)]\s/i)
      questions << {
        section:  current_section,
        question: stripped.sub(/\A[\da-z][.)]\s*/i, ''),
        raw:      stripped
      }
    end
  end

  { result: questions, count: questions.length }
end