<commit_before>require 'date'

class Job < Hash
  require 'khronotab/crontypes'

  def initialize(data)
    self[:minutes] = expand_field(data[:minutes], Minutes.new)
    self[:hours] = expand_field(data[:hours], Hours.new)
    self[:days_of_month] = expand_field(data[:days_of_month], DaysOfMonth.new)
    self[:month] = expand_field(data[:month], Months.new)
    self[:days_of_week] = expand_field(data[:days_of_week], DaysOfWeek.new)
    self[:user] = data[:user]
    self[:command] = data[:command]
  end

  def expand_field(cron_data, data_type)
    #---------------------------------------------------------
    # The data_type.new will have the max and min for that type
    #--------------------------------------------------------
    #return an array composed of all the valid fields values
    #so that self[:field_name].include[value] will return true
    #as a check to if the value runs today
      values = Array.new
      cron_data.split(',').each do |segment|
        case segment
          when /-/ #range
            range = segment.split('-').map! { |x| x.to_i }
            values.concat((range[0] .. range[1]).to_a)
          when /\// #interval
            count = 0
            interval = segment.split('/').map! { |x|
              if x == '*'
                x = data_type.maximum
              else
                x.to_i
              end
            }
            values.push(count += interval[1]) while count < interval[0]
          when /[*]/
            values.concat((data_type.minimum .. data_type.maximum).to_a)
          else
            values << segment.to_i
        end
      end
    return values
  end

  def runs_on?(date_to_check)
    puts date_to_check.to_s
    true
  end

  def runs_today?
    runs_on?(Date.today)
  end

  #def to_s
  #  puts "<Job name: %s, value: '%s' >" % [ self[:name], self[:value] ]
  #end
<commit_msg>Fixing Interval parsing and added sort+uniq<commit_after>require 'date'

class Job < Hash
  require 'khronotab/crontypes'

  def initialize(data)
    self[:minutes] = expand_field(data[:minutes], Minutes.new)
    self[:hours] = expand_field(data[:hours], Hours.new)
    self[:days_of_month] = expand_field(data[:days_of_month], DaysOfMonth.new)
    self[:month] = expand_field(data[:month], Months.new)
    self[:days_of_week] = expand_field(data[:days_of_week], DaysOfWeek.new)
    self[:user] = data[:user]
    self[:command] = data[:command]
  end

  def expand_field(cron_data, data_type)
    #---------------------------------------------------------
    # The data_type.new will have the max and min for that type
    #--------------------------------------------------------
    #return an array composed of all the valid fields values
    #so that self[:field_name].include[value] will return true
    #as a check to if the value runs today
      values = Array.new
      cron_data.split(',').each do |segment|
        case segment
          when /-/ #range
            range = segment.split('-').map! { |x| x.to_i }
            values.concat((range[0] .. range[1]).to_a)
          when /\// #interval
            counter = 0
            interval = segment.split('/').map! { |x|
              if x == '*'
                x = data_type.maximum
              else
                x.to_i
              end
            }
            while counter < interval[0]
              values.push(counter)
              counter += interval[1]
            end
          when /[*]/
            values.concat((data_type.minimum .. data_type.maximum).to_a)
          else
            values << segment.to_i
        end
      end
    return values.sort.uniq
  end

  def runs_on?(date_to_check)
    puts date_to_check.to_s
    true
  end

  def runs_today?
    runs_on?(Date.today)
  end

  #def to_s
  #  puts "<Job name: %s, value: '%s' >" % [ self[:name], self[:value] ]
  #end

{'fraction_non_alphanumeric': 0.176730869338886, 'fraction_numerical': 0.0026028110359187923, 'mean_word_length': 1.7727272727272727, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '3177431', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1162, 'n_words': 275}