olbrich/ruby-units

View on GitHub

Showing 33 of 62 total issues

File unit.rb has 1120 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "date"
module RubyUnits
  # Copyright 2006-2024
  # @author Kevin C. Olbrich, Ph.D.
  # @see https://github.com/olbrich/ruby-units
Severity: Major
Found in lib/ruby_units/unit.rb - About 2 days to fix

    Class Unit has 80 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Unit < ::Numeric
        class << self
          # return a list of all defined units
          # @return [Hash{Symbol=>RubyUnits::Units::Definition}]
          attr_accessor :definitions
    Severity: Major
    Found in lib/ruby_units/unit.rb - About 1 day to fix

      Method parse has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse(passed_unit_string = "0")
            unit_string = passed_unit_string.dup
            unit_string = "#{Regexp.last_match(1)} USD" if unit_string =~ /\$\s*(#{NUMBER_REGEX})/
            unit_string.gsub!("\u00b0".encode("utf-8"), "deg") if unit_string.encoding == Encoding::UTF_8
      
      
      Severity: Minor
      Found in lib/ruby_units/unit.rb - About 1 day to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      File standard.rb has 520 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      RubyUnits::Unit.define("inch") do |inch|
        inch.definition = RubyUnits::Unit.new("254/10000 meter")
        inch.aliases    = %w[in inch inches "]
      end
      
      
      Severity: Major
      Found in lib/ruby_units/unit_definitions/standard.rb - About 1 day to fix

        Method convert_to has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
        Open

            def convert_to(other)
              return self if other.nil?
              return self if other.is_a?(TrueClass)
              return self if other.is_a?(FalseClass)
        
        
        Severity: Minor
        Found in lib/ruby_units/unit.rb - About 7 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method parse has 138 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def parse(passed_unit_string = "0")
              unit_string = passed_unit_string.dup
              unit_string = "#{Regexp.last_match(1)} USD" if unit_string =~ /\$\s*(#{NUMBER_REGEX})/
              unit_string.gsub!("\u00b0".encode("utf-8"), "deg") if unit_string.encoding == Encoding::UTF_8
        
        
        Severity: Major
        Found in lib/ruby_units/unit.rb - About 5 hrs to fix

          Method to_s has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
          Open

              def to_s(target_units = nil, precision: 0.0001, format: RubyUnits.configuration.format)
                out = @output[target_units]
                return out if out
          
                separator = RubyUnits.configuration.separator
          Severity: Minor
          Found in lib/ruby_units/unit.rb - About 5 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method initialize has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
          Open

              def initialize(*options)
                @scalar      = nil
                @base_scalar = nil
                @unit_name   = nil
                @signature   = nil
          Severity: Minor
          Found in lib/ruby_units/unit.rb - About 5 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method to_base has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
          Open

              def to_base
                return self if base?
          
                if self.class.unit_map[units] =~ /\A<(?:temp|deg)[CRF]>\Z/
                  @signature = self.class.kinds.key(:temperature)
          Severity: Minor
          Found in lib/ruby_units/unit.rb - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method units has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

              def units(with_prefix: true, format: nil)
                return "" if @numerator == UNITY_ARRAY && @denominator == UNITY_ARRAY
          
                output_numerator   = ["1"]
                output_denominator = []
          Severity: Minor
          Found in lib/ruby_units/unit.rb - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method initialize has 72 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def initialize(*options)
                @scalar      = nil
                @base_scalar = nil
                @unit_name   = nil
                @signature   = nil
          Severity: Major
          Found in lib/ruby_units/unit.rb - About 2 hrs to fix

            Method convert_to has 56 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def convert_to(other)
                  return self if other.nil?
                  return self if other.is_a?(TrueClass)
                  return self if other.is_a?(FalseClass)
            
            
            Severity: Major
            Found in lib/ruby_units/unit.rb - About 2 hrs to fix

              Method to_s has 50 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def to_s(target_units = nil, precision: 0.0001, format: RubyUnits.configuration.format)
                    out = @output[target_units]
                    return out if out
              
                    separator = RubyUnits.configuration.separator
              Severity: Minor
              Found in lib/ruby_units/unit.rb - About 2 hrs to fix

                Method - has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                    def -(other)
                      case other
                      when Unit
                        if zero?
                          if other.zero?
                Severity: Minor
                Found in lib/ruby_units/unit.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method ** has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                    def **(other)
                      raise ArgumentError, "Cannot raise a temperature to a power" if temperature?
                
                      if other.is_a?(Numeric)
                        return inverse if other == -1
                Severity: Minor
                Found in lib/ruby_units/unit.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method + has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    def +(other)
                      case other
                      when Unit
                        if zero?
                          other.dup
                Severity: Minor
                Found in lib/ruby_units/unit.rb - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method to_base has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def to_base
                      return self if base?
                
                      if self.class.unit_map[units] =~ /\A<(?:temp|deg)[CRF]>\Z/
                        @signature = self.class.kinds.key(:temperature)
                Severity: Minor
                Found in lib/ruby_units/unit.rb - About 1 hr to fix

                  Method units has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def units(with_prefix: true, format: nil)
                        return "" if @numerator == UNITY_ARRAY && @denominator == UNITY_ARRAY
                  
                        output_numerator   = ["1"]
                        output_denominator = []
                  Severity: Minor
                  Found in lib/ruby_units/unit.rb - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                          if (other.is_a?(Unit) && other.temperature?) || (other.is_a?(String) && other =~ self.class.temp_regex)
                            raise ArgumentError, "Receiver is not a temperature unit" unless degree?
                    
                            start_unit = units
                            # @type [String]
                    Severity: Critical
                    Found in lib/ruby_units/unit.rb - About 1 hr to fix

                      Method / has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def /(other)
                            case other
                            when Unit
                              raise ZeroDivisionError if other.zero?
                              raise ArgumentError, "Cannot divide with temperatures" if [other, self].any?(&:temperature?)
                      Severity: Minor
                      Found in lib/ruby_units/unit.rb - About 1 hr to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Severity
                      Category
                      Status
                      Source
                      Language