<commit_before>module Sower
  module Relation
    class Statement
      # Initialialize a statement where attribute and values are used between the connector
      def initialize(attribute,value)
        @attribute = attribute
        @value = value
      end

      # Create a new AndStatement with self as attribute and statement as value
      # It is a simple chaining
      def where(state)
        AndStatement.new(self, state)
      end
      alias and where

      # Create a new OrStatement with self as attribute and statement as value
      # It is a simple chaining
      def or(state)
        OrStatement.new(self, state)
      end

      # Generate a SQL String well formatted
      # TODO SQL string must be handled by a SQL formatter ... no matter for now
      def to_sql
        [@attribute.to_sql,@value.to_sql].compact.join(' ')
      end

      # Return a Hash of attributes indexed by table
      def attributes
        [@attribute,@value].inject(Hash.new([])) do |memo,c|
          case c 
          when Sower::Relation::Statement
            memo.merge!(c.attributes){|k,v,n| v | n}
          when Sower::Relation::Attribute
            memo[c.table] |= [c]
          end
          memo
        end
      end

      protected
      # Generate brackets around the value of the yielded block
      def paren
        res = yield.to_s.strip
        res.empty? ? nil : "(#{res})"
      end

    end

    class AndStatement < Statement
      # Generate a SQL String well formatted
      # TODO SQL string must be handled by a SQL formatter ... no matter for now
      def to_sql
        [paren{@attribute.to_sql},paren{@value.to_sql}].compact.join(" \nAND " )
      end
    end

    class OrStatement < Statement
      # Generate a SQL String well formatted
      # TODO SQL string must be handled by a SQL formatter ... no matter for now
      def to_sql
        "(#{@attribute.to_sql}) \nOR (#{@value.to_sql})"
      end
    end

    module Stateable
      ##
      # :attr_reader: statement
      def statement<commit_msg>OrStatement to_sql must use #paren<commit_after>module Sower
  module Relation
    class Statement
      # Initialialize a statement where attribute and values are used between the connector
      def initialize(attribute,value)
        @attribute = attribute
        @value = value
      end

      # Create a new AndStatement with self as attribute and statement as value
      # It is a simple chaining
      def where(state)
        AndStatement.new(self, state)
      end
      alias and where

      # Create a new OrStatement with self as attribute and statement as value
      # It is a simple chaining
      def or(state)
        OrStatement.new(self, state)
      end

      # Generate a SQL String well formatted
      # TODO SQL string must be handled by a SQL formatter ... no matter for now
      def to_sql
        [@attribute.to_sql,@value.to_sql].compact.join(' ')
      end

      # Return a Hash of attributes indexed by table
      def attributes
        [@attribute,@value].inject(Hash.new([])) do |memo,c|
          case c 
          when Sower::Relation::Statement
            memo.merge!(c.attributes){|k,v,n| v | n}
          when Sower::Relation::Attribute
            memo[c.table] |= [c]
          end
          memo
        end
      end

      protected
      # Generate brackets around the value of the yielded block
      def paren
        res = yield.to_s.strip
        res.empty? ? nil : "(#{res})"
      end

    end

    class AndStatement < Statement
      # Generate a SQL String well formatted
      # TODO SQL string must be handled by a SQL formatter ... no matter for now
      def to_sql
        [paren{@attribute.to_sql},paren{@value.to_sql}].compact.join(" \nAND " )
      end
    end

    class OrStatement < Statement
      # Generate a SQL String well formatted
      # TODO SQL string must be handled by a SQL formatter ... no matter for now
      def to_sql
        [paren{@attribute.to_sql},paren{@value.to_sql}].compact.join(" \nOR " )
      end
    end

    module Stateable
      ##
      # :attr_reader: statement
      def statement
{'fraction_non_alphanumeric': 0.07599225556631171, 'fraction_numerical': 0.0, 'mean_word_length': 2.047935103244838, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '644673', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1115, 'n_words': 418}