Module: Boogex
- Defined in:
- lib/boogex.rb,
lib/boogex/error.rb,
lib/boogex/version.rb,
lib/boogex/convertor.rb
Defined Under Namespace
Modules: Helper
Constant Summary collapse
- Error =
Class.new(StandardError)
- VERSION =
'0.1.2'- AND_REGEX =
/ AND /- OR_REGEX =
/ OR /- NOT_REGEX =
/ NOT /
Class Method Summary collapse
- .convert(text) ⇒ Object
- .run_through_convertors(text) ⇒ Object
- .validate_regex_syntax!(regex, text) ⇒ Object
Class Method Details
.convert(text) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/boogex/convertor.rb', line 7 def self.convert(text) texts = text.split(NOT_REGEX) fail "The regex '#{text}' split more than twice on 'NOT'" if texts.size > 2 inclu_text = texts[0] exclu_text = texts[1] regex_hash = { inclusive_regex: run_through_convertors(inclu_text) } unless exclu_text.nil? regex_hash[:exclusive_regex] = run_through_convertors(exclu_text) regex_hash[:no_links] = true if exclu_text.include?('HTTP') validate_regex_syntax!(regex_hash[:exclusive_regex], text) end validate_regex_syntax!(regex_hash[:inclusive_regex], text) regex_hash end |
.run_through_convertors(text) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/boogex/convertor.rb', line 31 def self.run_through_convertors(text) array = array_struct(text) array = ors_to_pipes(array) array = regex_formatting(array) regex_array_to_string(array) end |
.validate_regex_syntax!(regex, text) ⇒ Object
26 27 28 29 |
# File 'lib/boogex/convertor.rb', line 26 def self.validate_regex_syntax!(regex, text) # Note: This also checks that the regex is valid and returns RegExpError if it isn't including a description of what went wrong. fail "#{regex} matched on nothing or empty space. Huh?" if !' '.match(regex).nil? end |