<commit_before>#ProductCard
#!/usr/bin/env ruby -wKU

require 'json'
require 'active_model'
require 'uri'

	class ProductCard
        include ActiveModel::Validations

		attr_accessor :cardType, :name, :webUrl, :productId, :merchant, :brand, :description, :colors, :images, :rating, :ratingScale, :ratingCount, :relatedItems, :referencedItems, :sizes, :options, :model, :appLinkIos, :appLinkAndroid

		attr_reader :offers
       # validates_presence_of :cardType
        validates :cardType, presence: true, inclusion: {in: %w(product product_search) }
		validates :webUrl, presence: true
		##todo URL regex validation
		#validates :webUrl, format: { with: /\A#{URI::regexp}\z/, on: :create}

		validates :name, presence: true

		#validate :offers_valid


		def initialize(attributes = {})
			attributes.each do |name, value|
				send("#{name}=", value)
				puts name
				puts value
			end	

		end

		def offers=(offers)

			if !offers.is_a?(Array)
				errors.add(:geographicAvailability, 'Must be an array!')
			end

			if offers.nil? || offers.empty? 
				errors.add(:offers, 'Must have atleast one offer!!')
			end

			tempOffer = Offer.new
			for index in 0 ... offers.size
				#it'd be nice to do Offer.new (offers[index]) so activemodel validation can do all the work for us
				#tempOffer.validateOffer(offers[index])
			end

			self.offers = offers

		end
		
		def writeAsJson
			puts self.to_json
		end <commit_msg>added validations to fields for ProductCard<commit_after>#ProductCard
#!/usr/bin/env ruby -wKU

require 'json'
require 'active_model'
require 'uri'

	class ProductCard
        include ActiveModel::Validations

		attr_accessor :cardType, :name, :webUrl, :productId, :merchant, :brand, :description, :images, :rating, :ratingScale, :ratingCount, :relatedItems, :referencedItems, :sizes, :options, :model, :appLinkIos, :appLinkAndroid

		attr_reader :offers, :colors
       # validates_presence_of :cardType
        validates :cardType, presence: true, inclusion: {in: %w(product product_search) }
		validates :webUrl, presence: true
		##todo URL regex validation
		#validates :webUrl, format: { with: /\A#{URI::regexp}\z/, on: :create}

		validates :name, presence: true

		#validate :offers_valid

		valid_colors = %w(Beige, Black, Blue, Bronze, Brown, Gold, Green, Gray, Metallic, Multicolored, OffWhite, Orange, Pink, Purple, Red, Silver, Transparent, Turquoise, White, Yellow)

		def initialize(attributes = {})
			attributes.each do |name, value|
				send("#{name}=", value)
				puts name
				puts value
			end	

		end

		def offers=(offers)

			if !offers.is_a?(Array)
				errors.add(:geographicAvailability, 'Must be an array!')
			end

			if offers.nil? || offers.empty? 
				errors.add(:offers, 'Must have atleast one offer!!')
			end

			tempOffer = Offer.new
			for index in 0 ... offers.size
				#it'd be nice to do Offer.new (offers[index]) so activemodel validation can do all the work for us
				#tempOffer.validateOffer(offers[index])
			end

			self.offers = offers

		end

		def colors=(colors)

			if !colors.is_a?(Array)
				errors.add(:colors, 'Must be an array!')
			end

			for index in 0 ... colors.size
				if (self.valid_colors.include? colors[index])
					errors.add(:colors, 'Invalid Color Added')
				end
			end

			self.colors = colors
		
		end

		
		def writeAsJson
			puts self.to_json
		end 
{'fraction_non_alphanumeric': 0.11864913329348475, 'fraction_numerical': 0.0008965929468021519, 'mean_word_length': 3.7207334273624824, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2814358', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1094, 'n_words': 323}