<commit_before>require "thor"
require_relative "./closed_auction"
require_relative "./detailed_auction"

def all_valid_columns
	return ["title", "url", "end_price", "end_date", "start_price", "start_date"]
end

class CLI < Thor
	desc "search ", "Search with passed word"
	option "max", type: :string
	option "min", type: :string
	option "outputs", type: :array
	option "page", type: :numeric, default: 1
	option "all", type: :boolean
	def search(word)
		client = ClosedAuction::Client.new
		query = ClosedAuction::SearchQuery.new(word, 
																					 min: options[:min], 
																					 max: options[:max], 
																					 page: options[:page]
																					)

		entries = options[:all] ? client.search_all(query) : client.search(query)
		print_entries(entries, options[:outputs])
	end

	option "max", type: :string
	option "min", type: :string
	option "all", type: :boolean
	option "page", type: :numeric, default: 1
	desc "avr WORD", "Just obtain the average of end price of closed auction"
	def avr(word)
		client = ClosedAuction::Client.new
		query = ClosedAuction::SearchQuery.new(word, 
																					 min: options[:min], 
																					 max: options[:max], 
																					 page: options[:page]
																					)

		entries = options[:all] ? client.search_all(query) : client.search(query)
		puts entries.inject(0){|r, i| r += i.end_price}.to_f / entries.count
	end


	# outputs: columns to be displayed
	def print_entries(entries, outputs)
		if outputs.nil? || outputs.empty?
			entries.each do |e|
				puts "#{e.title}, #{e.end_price}, #{e.end_date}"
				puts "#{e.url}"
			end
		else
			columns = outputs.select{|o| all_valid_columns.include? o}
			puts columns.join(",")
			entries.each do |e|
				puts columns.map{|c| e.send(c.to_sym)}.join(",")
			end<commit_msg>FIX: remove unnecessary option declaration in cli<commit_after>require "thor"
require_relative "./closed_auction"
require_relative "./detailed_auction"

def all_valid_columns
	return ["title", "url", "end_price", "end_date", "start_price", "start_date"]
end

class CLI < Thor
	class_option "max", type: :string
	class_option "min", type: :string
	class_option "page", type: :numeric, default: 1
	class_option "all", type: :boolean

	desc "search ", "Search with passed word"
	option "outputs", type: :array
	def search(word)
		client = ClosedAuction::Client.new
		query = ClosedAuction::SearchQuery.new(word, 
																					 min: options[:min], 
																					 max: options[:max], 
																					 page: options[:page]
																					)

		entries = options[:all] ? client.search_all(query) : client.search(query)
		print_entries(entries, options[:outputs])
	end

	desc "avr WORD", "Just obtain the average of end price of closed auction"
	def avr(word)
		client = ClosedAuction::Client.new
		query = ClosedAuction::SearchQuery.new(word, 
																					 min: options[:min], 
																					 max: options[:max], 
																					 page: options[:page]
																					)

		entries = options[:all] ? client.search_all(query) : client.search(query)
		puts entries.inject(0){|r, i| r += i.end_price}.to_f / entries.count
	end


	# outputs: columns to be displayed
	def print_entries(entries, outputs)
		if outputs.nil? || outputs.empty?
			entries.each do |e|
				puts "#{e.title}, #{e.end_price}, #{e.end_date}"
				puts "#{e.url}"
			end
		else
			columns = outputs.select{|o| all_valid_columns.include? o}
			puts columns.join(",")
			entries.each do |e|
				puts columns.map{|c| e.send(c.to_sym)}.join(",")
			end
{'fraction_non_alphanumeric': 0.13788300835654596, 'fraction_numerical': 0.001392757660167131, 'mean_word_length': 2.9635761589403975, 'pattern_counts': {'":': 0, '<': 5, '<?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': '266694', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1116, 'n_words': 297}