lib/appstats/parser.rb in appstats-0.19.7 vs lib/appstats/parser.rb in appstats-0.20.0

- old
+ new

@@ -71,17 +71,31 @@ remove_tokens_at_start(@text_so_far) unset_rules_until(nil) true end + def self.alpha?(raw_input) + return false if raw_input.nil? + !raw_input.match(/^[A-Za-z]+$/i).nil? + end + def self.parse_constant(current_text,constant) answer = [nil,nil] return answer if current_text.blank? || constant.nil? current_text.strip! - m = current_text.match(/^(#{constant})(.*)$/im) + + remaining_text_index = -1 + if alpha?(constant) + m = current_text.match(/^(#{constant})(\s|$)(.*)$/im) + remaining_text_index = 3 + else + m = current_text.match(/^(#{constant})(.*)$/im) + remaining_text_index = 2 + end + answer[0] = m[1] unless m.nil? - answer[1] = m.nil? ? current_text : m[2] + answer[1] = m.nil? ? current_text : m[remaining_text_index] clean_parsed_word(answer) end def self.merge_regex_filter(inputs = []) inputs.collect! { |x| x unless x.blank? }.compact! @@ -184,11 +198,11 @@ current_token = token.upcase current_token.gsub!("(",'\(') current_token.gsub!(")",'\)') current_token.gsub!("|",'\|') @tokenize_no_spaces<< current_token - current_token = "\\s+#{current_token}" unless current_token.match(/.*[a-z].*/i).nil? + current_token = "\\s+#{current_token}(\\s|$)" unless current_token.match(/.*[a-z].*/i).nil? @tokenize<< current_token end @tokenize_regex_no_spaces = @tokenize_no_spaces.join("|") @tokenize_regex = @tokenize.join("|") end @@ -207,10 +221,10 @@ previous_stop_on = :space else current_rule = rule.upcase current_rule_no_spaces = current_rule @constants_no_spaces<< current_rule_no_spaces - current_rule = "\\s+#{current_rule}" unless current_rule.match(/.*[a-z].*/i).nil? + current_rule = "\\s+#{current_rule}(\\s|$)" unless current_rule.match(/.*[a-z].*/i).nil? @constants<< current_rule previous_stop_on = :constant end if @rules.last.kind_of?(Hash) \ No newline at end of file