<commit_before>require 'ib/messages/abstract_message'
require 'ib/support'
require 'ox'

module IBSupport
	refine Array do

		def zero?
			false
		end
		# Returns the integer. 
		# retuns nil otherwise or if no element is left on the stack
		def read_int
			i= self.shift  rescue nil
			i = i.to_i unless i.blank?			# this includes conversion of string to zero(0)
			i.is_a?( Integer ) ?  i : nil
		end

		def read_decimal
			i= self.shift  rescue nil
			i = i.to_d unless i.blank?
			i.is_a?(Numeric)  && i < IB::TWS_MAX ?  i : nil  # return nil, if a very large number is transmitted
		end

		alias read_decimal_max read_decimal

		## Values -1 and below indicate: Not computed (TickOptionComputation)
		def read_decimal_limit_1
			i= read_decimal
			i <= -1 ? nil : i
		end

		## Values -2 and below indicate: Not computed (TickOptionComputation)
		def read_decimal_limit_2
			i= read_decimal
			i <= -2 ? nil : i
		end


		def read_string
			self.shift rescue ""
		end
		## reads a string and proofs if NULL ==  IB::TWS_MAX is present.
		## in that case: returns nil. otherwise: returns the string
		def read_string_not_null
			r = read_string
			rd = r.to_d  unless r.blank?
			rd.is_a?(Numeric) && rd >= IB::TWS_MAX ? nil : r
		end

		def read_symbol
			read_string.to_sym
		end

		# convert xml into a hash
		def read_xml
			Ox.load( read_string(), mode: :hash_no_attrs)
		end


		def read_int_date
			Time.at read_int
		end

		def read_boolean

			v = self.shift  rescue nil
			case v
			when "1"
				true
			when "0"
				false
			else nil
			end
		end


		#LIKUOLIN edit
		def read_date
			the_string = read_string
			if the_string.blank?
				return nil
			else 
				return Date.parse(the_string)				<commit_msg>print out weird dates!<commit_after>require 'ib/messages/abstract_message'
require 'ib/support'
require 'ox'

module IBSupport
	refine Array do

		def zero?
			false
		end
		# Returns the integer. 
		# retuns nil otherwise or if no element is left on the stack
		def read_int
			i= self.shift  rescue nil
			i = i.to_i unless i.blank?			# this includes conversion of string to zero(0)
			i.is_a?( Integer ) ?  i : nil
		end

		def read_decimal
			i= self.shift  rescue nil
			i = i.to_d unless i.blank?
			i.is_a?(Numeric)  && i < IB::TWS_MAX ?  i : nil  # return nil, if a very large number is transmitted
		end

		alias read_decimal_max read_decimal

		## Values -1 and below indicate: Not computed (TickOptionComputation)
		def read_decimal_limit_1
			i= read_decimal
			i <= -1 ? nil : i
		end

		## Values -2 and below indicate: Not computed (TickOptionComputation)
		def read_decimal_limit_2
			i= read_decimal
			i <= -2 ? nil : i
		end


		def read_string
			self.shift rescue ""
		end
		## reads a string and proofs if NULL ==  IB::TWS_MAX is present.
		## in that case: returns nil. otherwise: returns the string
		def read_string_not_null
			r = read_string
			rd = r.to_d  unless r.blank?
			rd.is_a?(Numeric) && rd >= IB::TWS_MAX ? nil : r
		end

		def read_symbol
			read_string.to_sym
		end

		# convert xml into a hash
		def read_xml
			Ox.load( read_string(), mode: :hash_no_attrs)
		end


		def read_int_date
			Time.at read_int
		end

		def read_boolean

			v = self.shift  rescue nil
			case v
			when "1"
				true
			when "0"
				false
			else nil
			end
		end


		#LIKUOLIN edit
		def read_date
			the_string = read_string
			if the_string.blank?
				return nil
			else 
				
				begin
					date = Date.parse(the_string)				
				rescue Exception => e
					p "======================================="
					puts the_string					
				end		
				
				return date
{'fraction_non_alphanumeric': 0.0847457627118644, 'fraction_numerical': 0.005001389274798555, 'mean_word_length': 2.669724770642202, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5155399', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1275, 'n_words': 421}