<commit_before>module DBF
  # An instance of DBF::Record represents a row in the DBF file 
  class Record
    # Initialize a new DBF::Record
    # 
    # @param [DBF::Table] table
    def initialize(data, columns, version, memo)
      @data = StringIO.new(data)
      @columns, @version, @memo = columns, version, memo
      @column_names = @columns.map {|column| column.underscored_name}
      define_accessors
    end
    
    # Equality
    #
    # @param [DBF::Record] other
    # @return [Boolean]
    def ==(other)
      other.respond_to?(:attributes) && other.attributes == attributes
    end
    
    # Maps a row to an array of values
    # 
    # @return [Array]
    def to_a
      @column_names.map { |name| attributes[name] }
    end
    
    # Do all search parameters match?
    #
    # @param [Hash] options
    # @return [Boolean]
    def match?(options)
      options.all? {|key, value| attributes[Util.underscore(key.to_s)] == value}
    end
    
    # @return [Hash]
    def attributes
      return @attributes if @attributes
      
      @attributes = Attributes.new
      @columns.each do |column|
        @attributes[column.name] = init_attribute(column)
      end
      @attributes
    end
    
    private
    
    def define_accessors #nodoc
      @column_names.each do |name|
        next if respond_to? name
        self.class.class_eval <<-END
          def #{name}
            @#{name} ||= attributes['#{name}']
          end
        END
      end
    end
    
    def init_attribute(column) #nodoc
      if column.memo?
        @memo.get get_memo_start_block(column)
      else
        column.type_cast unpack_data(column)
      end
    end<commit_msg>memo columns return nil when no memo file found<commit_after>module DBF
  # An instance of DBF::Record represents a row in the DBF file 
  class Record
    # Initialize a new DBF::Record
    # 
    # @param [DBF::Table] table
    def initialize(data, columns, version, memo)
      @data = StringIO.new(data)
      @columns, @version, @memo = columns, version, memo
      @column_names = @columns.map {|column| column.underscored_name}
      define_accessors
    end
    
    # Equality
    #
    # @param [DBF::Record] other
    # @return [Boolean]
    def ==(other)
      other.respond_to?(:attributes) && other.attributes == attributes
    end
    
    # Maps a row to an array of values
    # 
    # @return [Array]
    def to_a
      @column_names.map { |name| attributes[name] }
    end
    
    # Do all search parameters match?
    #
    # @param [Hash] options
    # @return [Boolean]
    def match?(options)
      options.all? {|key, value| attributes[Util.underscore(key.to_s)] == value}
    end
    
    # @return [Hash]
    def attributes
      return @attributes if @attributes
      
      @attributes = Attributes.new
      @columns.each do |column|
        @attributes[column.name] = init_attribute(column)
      end
      @attributes
    end
    
    private
    
    def define_accessors #nodoc
      @column_names.each do |name|
        next if respond_to? name
        self.class.class_eval <<-END
          def #{name}
            @#{name} ||= attributes['#{name}']
          end
        END
      end
    end
    
    def init_attribute(column) #nodoc
      if column.memo?
        @memo.get get_memo_start_block(column) if @memo
      else
        column.type_cast unpack_data(column)
      end
    end
{'fraction_non_alphanumeric': 0.10184913413560318, 'fraction_numerical': 0.0, 'mean_word_length': 2.158480074142725, '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': '3990433', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1061, 'n_words': 285}