Class: HREP

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

Overview

HrefRegexpParser

Class Method Summary collapse

Class Method Details

.parse(regexp: nil, lines: [], block_list: [], must_have_list: []) ⇒ Object

splits lines into parts according to the given regexp rule. It extracts the block_list containing the words and checks if the must_have_list contains all the words.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/hrep.rb', line 4

def self.parse(
      regexp: nil,
      lines:  [], 
      block_list: [], 
      must_have_list: [])
  return false unless check_given_parameters(lines, block_list, must_have_list, regexp)
  return [] if lines.empty?

  lines
    .select { |line| line.match?(regexp) }
    .map    { |line| line.match(regexp).captures }
    .select { |captures| include_all_must_have_word?(must_have_list, captures) }
    .reject { |captures| include_any_block_list_word?(block_list, captures) }
end