<commit_before>module Stripe
  module Coupons
    include ConfigurationBuilder

    configuration_for :coupon do
      attr_accessor :duration, :amount_off, :currency, :duration_in_months, :max_redemptions, :percent_off, :redeem_by

      validates_presence_of :id, :duration
      validates_presence_of :duration_in_months, :if => :repeating?
      validates_inclusion_of :duration, :in => %w(forever once repeating), :message => "'%{value}' is not one of 'forever', 'once' or 'repeating'"
      validates_inclusion_of :percent_off, in: 1..100, unless: ->(coupon) {coupon.percent_off.nil?}
      validates_numericality_of :percent_off, :greater_than => 0
      validates_numericality_of :duration_in_months, :greater_than => 0, :if => :repeating?
      validates_numericality_of :max_redemptions, greater_than: 0, unless: ->(coupon) {coupon.max_redemptions.nil?}

      def initialize(*args)
        super
        @currency = 'usd'
      end

      def repeating?
        duration == 'repeating'
      end

      def create_options
        {
          :duration => duration,
          :percent_off => percent_off,
          :amount_off => amount_off,
          :currency => currency,
          :duration_in_months => duration_in_months,
          :max_redemptions => max_redemptions,
          :redeem_by => redeem_by
        }
      end
    end
  end
end<commit_msg>don't run percent off validations if it's nil<commit_after>module Stripe
  module Coupons
    include ConfigurationBuilder

    configuration_for :coupon do
      attr_accessor :duration, :amount_off, :currency, :duration_in_months, :max_redemptions, :percent_off, :redeem_by

      validates_presence_of :id, :duration
      validates_presence_of :duration_in_months, :if => :repeating?
      validates_inclusion_of :duration, :in => %w(forever once repeating), :message => "'%{value}' is not one of 'forever', 'once' or 'repeating'"
      validates_inclusion_of :percent_off, in: 1..100, unless: ->(coupon) {coupon.percent_off.nil?}
      validates_numericality_of :percent_off, :greater_than => 0, unless: ->(coupon) {coupon.percent_off.nil?}
      validates_numericality_of :duration_in_months, :greater_than => 0, :if => :repeating?
      validates_numericality_of :max_redemptions, greater_than: 0, unless: ->(coupon) {coupon.max_redemptions.nil?}

      def initialize(*args)
        super
        @currency = 'usd'
      end

      def repeating?
        duration == 'repeating'
      end

      def create_options
        {
          :duration => duration,
          :percent_off => percent_off,
          :amount_off => amount_off,
          :currency => currency,
          :duration_in_months => duration_in_months,
          :max_redemptions => max_redemptions,
          :redeem_by => redeem_by
        }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1041222459132907, 'fraction_numerical': 0.004975124378109453, 'mean_word_length': 3.127565982404692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, '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': '6679612', 'n_tokens_mistral': 940, 'n_tokens_neox': 903, 'n_words': 199}