<commit_before>module Parsable
  class Parser

    attr_accessor :original_string, :strings

    def initialize args={}
      @original_string = args.fetch(:string).to_s
      @strings         = all_captures(@original_string)
    end

    def parse
      strings.uniq.collect do |string|
        function, object, attribute = capture(string)

        Parsable::ParsedItem.new(\
          :original  => string, 
          :function  => function,
          :object    => object,
          :attribute => attribute
        )
      end
    end

    private

    def capture string
      [capture_function_method(string), capture_object(string), capture_attribute(string)]
    end

    def all_captures string
      string.to_s.scan(/\{\{(\w*\(?\w*\.?\w*\)?)\}\}/).flatten
    end

    def capture_function_method string
      match = string.match(/(.*)\(.*\)/)
      match[1] if match
    end

    def capture_attribute string
      object_attribute(string).last
    end

    def capture_object string
      object_attribute(string).first
    end

    def object_attribute string
      string.match(/(\w*\.\w*)/)[1].split('.')
    end

  end

end<commit_msg>return nil if no match at all<commit_after>module Parsable
  class Parser

    attr_accessor :original_string, :strings

    def initialize args={}
      @original_string = args.fetch(:string).to_s
      @strings         = all_captures(@original_string)
    end

    def parse
      strings.uniq.collect do |string|
        function, object, attribute = capture(string)

        Parsable::ParsedItem.new(\
          :original  => string, 
          :function  => function,
          :object    => object,
          :attribute => attribute
        )
      end
    end

    private

    def capture string
      [capture_function_method(string), capture_object(string), capture_attribute(string)]
    end

    def all_captures string
      string.to_s.scan(/\{\{(\w*\(?\w*\.?\w*\)?)\}\}/).flatten
    end

    def capture_function_method string
      match = string.match(/(.*)\(.*\)/)
      match[1] if match
    end

    def capture_attribute string
      object_attribute(string).last
    end

    def capture_object string
      object_attribute(string).first
    end

    def object_attribute string
      string.match[/(\w*\.\w*)/, 1].to_s.split('.')
    end

  end

end
{'fraction_non_alphanumeric': 0.11860764933390631, 'fraction_numerical': 0.0017189514396218307, 'mean_word_length': 2.2378303198887344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2188765', 'n_tokens_mistral': 714, 'n_tokens_neox': 680, 'n_words': 154}