Module: Readlines::Pattern

Included in:
ReadDuc
Defined in:
lib/readlines/readlines/pattern.rb

Instance Method Summary collapse

Instance Method Details

#extract_patterns_now(patterns) ⇒ Object

Raises:

  • (Readlines::NotFoundError)


15
16
17
18
19
20
# File 'lib/readlines/readlines/pattern.rb', line 15

def extract_patterns_now(patterns)
    raise Readlines::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path)

    content = ::File.read(@file_path)
    patterns.flat_map { |pattern| content.scan(pattern) }
end

#pattern_exists_now?(pattern) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (Readlines::NotFoundError)


8
9
10
11
12
13
# File 'lib/readlines/readlines/pattern.rb', line 8

def pattern_exists_now?(pattern)
    raise Readlines::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path)

    content = ::File.read(@file_path)
    content.match?(pattern)
end