<commit_before>require 'will_paginate/array'

class DataController < ApplicationController
  Datum = Struct.new(:id, :name)

  DATA = (1..100).map do |i|
    Datum.new(i, "Name #{i}")
  end.shuffle

  def DATA.order(arg)
    column, direction = arg.split
    sorted_data = case column
    when 'name' then DATA.sort_by { |datum| datum[1] }
    when 'id' then DATA.sort_by { |datum| datum[0] }
    else raise "Invalid column: #{column}"
    end
    case direction
    when 'asc' then sorted_data
    when 'desc' then sorted_data.reverse
    else raise "Invalid direction: #{direction}"
    end
  end

  def index
    paginated_table('data', DATA, :defaults => { :sort_column => 'id' })
  end
end<commit_msg>Refactors test data, adds search feature<commit_after>require 'will_paginate/array'

class DataController < ApplicationController

  def index
    range =
      case params['search']
      when 'secondhalf' then (51..100)
      else (1..100)
      end
    paginated_table('data', data(range), :defaults => { :sort_column => 'id' })
  end

  private

  Datum = Struct.new(:id, :name)

  module OrderableData
    def order(arg)
      column, direction = arg.split
      sorted_data = case column
      when 'name' then sort_by { |datum| datum[1] }
      when 'id' then sort_by { |datum| datum[0] }
      else raise "Invalid column: #{column}"
      end
      case direction
      when 'asc' then sorted_data
      when 'desc' then sorted_data.reverse
      else raise "Invalid direction: #{direction}"
      end
    end
  end
    
  def data(ids)
    data = ids.map { |i| Datum.new(i, "Name #{i}") }
    data.shuffle!
    data.extend(OrderableData)
    data
  end
end
{'fraction_non_alphanumeric': 0.11909036505086774, 'fraction_numerical': 0.010173548773189706, 'mean_word_length': 2.8974358974358974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3622526', 'n_tokens_mistral': 558, 'n_tokens_neox': 546, 'n_words': 158}