olbrich/ruby-units

View on GitHub

Showing 62 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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                    @denominator.compact.each do |num_unit|
                      if self.class.prefix_values[num_unit]
                        q /= self.class.prefix_values[num_unit]
                      else
                        q /= self.class.unit_values[num_unit][:scalar] if self.class.unit_values[num_unit]
              Severity: Major
              Found in lib/ruby_units/unit.rb and 1 other location - About 2 hrs to fix
              lib/ruby_units/unit.rb on lines 627..634

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 82.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                    @numerator.compact.each do |num_unit|
                      if self.class.prefix_values[num_unit]
                        q *= self.class.prefix_values[num_unit]
                      else
                        q *= self.class.unit_values[num_unit][:scalar] if self.class.unit_values[num_unit]
              Severity: Major
              Found in lib/ruby_units/unit.rb and 1 other location - About 2 hrs to fix
              lib/ruby_units/unit.rb on lines 636..643

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 82.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              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
                    Severity
                    Category
                    Status
                    Source
                    Language