<commit_before>require 'delegate'
require 'time_span_serializer'

class TimeSpan < DelegateClass(Numeric)
  VERSION = "1.1.0"

  SECONDS_PER_MINUTE = 60.0
  SECONDS_PER_HOUR = 3600.0

  SECONDS_SERIALIZER = TimeSpanSerializer.new(:seconds)

  # interface used by libs like ActiveRecord to convert instances of TimeSpan to a string.
  def self.dump(value)
    SECONDS_SERIALIZER.dump(value)
  end

  # interface used by libs like ActiveRecord to convert strings to instances of TimeSpan.
  # this is designed to be flexible in input type. So it can be as a
  # generic "Create me a TimeSpan from this thing" method
  def self.load(value)
    SECONDS_SERIALIZER.load(value)
  end

  def self.from_seconds(seconds)
    new(seconds, :seconds)
  end

  def self.from_minutes(minutes)
    new(minutes, :minutes)
  end

  def self.from_hours(hours)
    new(hours, :hours)
  end

  # create a new TimeSpan with the specified
  def self.new(value, unit=:seconds)
    case unit
    when :seconds
      super(value)
    when :minutes
      super(value*SECONDS_PER_MINUTE)
    when :hours
      super(value*SECONDS_PER_HOUR)
    end
  end

  # return a new TimeSpan from a string
  def self.parse(value, unit=:seconds)
    new(value.to_f, unit)
  end

  def total_seconds
    self.to_f
  end

  def total_minutes
    self / SECONDS_PER_MINUTE
  end

  def total_hours
    self / SECONDS_PER_HOUR
  end

  def hours
    total_seconds.to_i / SECONDS_PER_HOUR.to_i
  end<commit_msg>Raise error if creating with nil value<commit_after>require 'delegate'
require 'time_span_serializer'

class TimeSpan < DelegateClass(Numeric)
  VERSION = "1.1.0"

  SECONDS_PER_MINUTE = 60.0
  SECONDS_PER_HOUR = 3600.0

  SECONDS_SERIALIZER = TimeSpanSerializer.new(:seconds)

  # interface used by libs like ActiveRecord to convert instances of TimeSpan to a string.
  def self.dump(value)
    SECONDS_SERIALIZER.dump(value)
  end

  # interface used by libs like ActiveRecord to convert strings to instances of TimeSpan.
  # this is designed to be flexible in input type. So it can be as a
  # generic "Create me a TimeSpan from this thing" method
  def self.load(value)
    SECONDS_SERIALIZER.load(value)
  end

  def self.from_seconds(seconds)
    new(seconds, :seconds)
  end

  def self.from_minutes(minutes)
    new(minutes, :minutes)
  end

  def self.from_hours(hours)
    new(hours, :hours)
  end

  # create a new TimeSpan with the specified
  def self.new(value, unit=:seconds)
    raise ArgumentError, "Value cannot be nil" if value.nil?
    case unit
    when :seconds
      super(value)
    when :minutes
      super(value*SECONDS_PER_MINUTE)
    when :hours
      super(value*SECONDS_PER_HOUR)
    end
  end

  # return a new TimeSpan from a string
  def self.parse(value, unit=:seconds)
    raise ArgumentError, "Value cannot be nil" if value.nil?
    new(value.to_f, unit)
  end

  def total_seconds
    self.to_f
  end

  def total_minutes
    self / SECONDS_PER_MINUTE
  end

  def total_hours
    self / SECONDS_PER_HOUR
  end

  def hours
    total_seconds.to_i / SECONDS_PER_HOUR.to_i
  end
{'fraction_non_alphanumeric': 0.0688088283024992, 'fraction_numerical': 0.007140538786108407, 'mean_word_length': 3.3592644978783595, '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': '1950787', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1051, 'n_words': 311}