<commit_before>#encoding: utf-8

module SY
  # This class represents a magnitude of a metrological quantity. A magnitude
  # is basically a pair [quantity, amount].
  # 
  class Magnitude
    include UnitMethodsMixin # ensuring that magnitudes respond to unit methods
    include Comparable

    # Constructor of magnitudes of a given quantity.
    # 
    def self.of *args
      ꜧ = args.extract_options!
      case args.size
      when 0 then new ꜧ
      when 1 then new ꜧ.merge!( quantity: args[0] )
      else
        raise ArgumentError, "Too many ordered arguments."
      end
    end

    attr_reader :quantity, :amount

    delegate :dimension,
             :dimensionless?,
             to: :quantity

    # A magnitude is basically a pair [quantity, number].
    # 
    def initialize *args
      hash = args.extract_options!
      @quantity = hash.must_have :quantity, syn!: :of
      raise TypeError, "Named argument :quantity must be of " +
        "SY::Quantity class." unless @quantity.is_a? ::SY::Quantity
      @amount = case am = hash[:amount] || 1
                when Magnitude then
                  tE_same_dimension( am )
                  am.numeric_value_in_standard_unit
                else am end
      raise NegativeAmountError, "Attempt to create a magnitude " +
        "with negative amount (#@amount)." unless @amount >= 0
    end

    # Absolute value of a Magnitude: A new magnitude instance with amount equal
    # to the absolute value of this magnitude's amount.
    # 
    def abs
      ::SY::Magnitude.of quantity, amount: amount.abs
    end

    # Rounded value of a Magnitude: A new magnitude with rounded amount.
    # 
    def round *args
      ç.of quantity, amount: amount.round *args
    end

    # Whether the magnitude is zero.
    # 
    delegate :zero?, to: amount

    # Magnitudes compare by their numbers. Compared magnitudes must be of
    # the same quantity.
    # <commit_msg>ongoing<commit_after>#encoding: utf-8

module SY
  # This class represents a magnitude of a metrological quantity. A magnitude
  # is basically a pair [quantity, amount].
  # 
  class Magnitude
    include UnitMethodsMixin # ensuring that magnitudes respond to unit methods
    include Comparable

    # Constructor of magnitudes of a given quantity.
    # 
    def self.of *args
      ꜧ = args.extract_options!
      case args.size
      when 0 then new ꜧ
      when 1 then new ꜧ.merge!( quantity: args[0] )
      else
        raise ArgumentError, "Too many ordered arguments."
      end
    end

    attr_reader :quantity, :amount

    delegate :dimension,
             :dimensionless?,
             to: :quantity

    # A magnitude is basically a pair [quantity, number].
    # 
    def initialize *args
      hash = args.extract_options!
      @quantity = hash.must_have :quantity, syn!: :of
      raise TypeError, "Named argument :quantity must be of " +
        "SY::Quantity class." unless @quantity.is_a? ::SY::Quantity
      @amount = case am = hash[:amount] || 1
                when Magnitude then
                  tE_same_dimension( am )
                  am.numeric_value_in_standard_unit
                else am end
      raise NegativeAmountError, "Attempt to create a magnitude " +
        "with negative amount (#@amount)." unless @amount >= 0
    end

    # Absolute value of a Magnitude: A new magnitude instance with amount equal
    # to the absolute value of this magnitude's amount.
    # 
    def abs
      ::SY::Magnitude.of quantity, amount: amount.abs
    end

    # Rounded value of a Magnitude: A new magnitude with rounded amount.
    # 
    def round *args
      ç.of quantity, amount: amount.round( *args )
    end

    # Whether the magnitude is zero.
    # 
    delegate :zero?, to: amount

    # Magnitudes compare by their numbers. Compared magnitudes must be of
    # the same quantity.
    # 
{'fraction_non_alphanumeric': 0.07347994825355757, 'fraction_numerical': 0.0031047865459249676, 'mean_word_length': 2.276271186440678, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1159412', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1018, 'n_words': 412}