Module: FromToUntil
- Defined in:
- from_to_until.rb
Overview
Jekyll filters for working with multiline strings.
Instance Method Summary collapse
-
#from(input_strings, regex) ⇒ String
Filters a multiline string, returning the portion beginning with the line that satisfies a regex.
-
#to(input_strings, regex) ⇒ Object
Filters a multiline string, returning the portion from the beginning until and including the line that satisfies a regex.
-
#until(input_strings, regex) ⇒ Object
Filters a multiline string, returning the portion from the beginning until but not including the line that satisfies a regex.
Instance Method Details
#from(input_strings, regex) ⇒ String
Filters a multiline string, returning the portion beginning with the line that satisfies a regex. The regex could be enclosed in single quotes, double quotes, or nothing.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'from_to_until.rb', line 14 def from(input_strings, regex) return '' unless check_parameters(input_strings, regex) regex = remove_quotations(regex.to_s.strip) matched = false result = '' input_strings.each_line do |line| matched = true if !matched && line =~ /#{regex}/ result += line if matched end result end |
#to(input_strings, regex) ⇒ Object
Filters a multiline string, returning the portion from the beginning until and including the line that satisfies a regex. The regex could be enclosed in single quotes, double quotes, or nothing.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'from_to_until.rb', line 31 def to(input_strings, regex) return '' unless check_parameters(input_strings, regex) regex = remove_quotations(regex.to_s.strip) result = '' input_strings.each_line do |line| result += line return result if line =~ /#{regex}/ end result end |
#until(input_strings, regex) ⇒ Object
Filters a multiline string, returning the portion from the beginning until but not including the line that satisfies a regex. The regex could be enclosed in single quotes, double quotes, or nothing.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'from_to_until.rb', line 47 def until(input_strings, regex) return '' unless check_parameters(input_strings, regex) regex = remove_quotations(regex.to_s.strip) result = '' input_strings.each_line do |line| return result if line =~ /#{regex}/ result += line end result end |