olbrich/ruby-units

View on GitHub
lib/ruby_units/unit.rb

Summary

Maintainability
F
2 wks
Test Coverage
A
95%

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

      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

                    Method <=> has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def <=>(other)
                          raise NoMethodError, "undefined method `<=>' for #{base_scalar.inspect}" unless base_scalar.respond_to?(:<=>)
                    
                          if other.nil?
                            base_scalar <=> nil
                    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 27 lines of code (exceeds 25 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

                      Method == has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def ==(other)
                            if other.respond_to?(:zero?) && other.zero?
                              zero?
                            elsif other.instance_of?(Unit)
                              return false unless self =~ other
                      Severity: Minor
                      Found in lib/ruby_units/unit.rb - About 55 mins 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 root has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def root(n)
                            raise ArgumentError, "Cannot take the root of a temperature" if temperature?
                            raise ArgumentError, "Exponent must an Integer" unless n.is_a?(Integer)
                            raise ArgumentError, "0th root undefined" if n.zero?
                            return self if n == 1
                      Severity: Minor
                      Found in lib/ruby_units/unit.rb - About 55 mins 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 unit_signature_vector has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def unit_signature_vector
                            return to_base.unit_signature_vector unless base?
                      
                            vector = ::Array.new(SIGNATURE_VECTOR.size, 0)
                            # it's possible to have a kind that misses the array... kinds like :counting
                      Severity: Minor
                      Found in lib/ruby_units/unit.rb - About 35 mins 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 power has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def power(n)
                            raise ArgumentError, "Cannot raise a temperature to a power" if temperature?
                            raise ArgumentError, "Exponent must an Integer" unless n.is_a?(Integer)
                            return inverse if n == -1
                            return 1 if n.zero?
                      Severity: Minor
                      Found in lib/ruby_units/unit.rb - About 35 mins 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

                      Avoid too many return statements within this method.
                      Open

                              return
                      Severity: Major
                      Found in lib/ruby_units/unit.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return
                        Severity: Major
                        Found in lib/ruby_units/unit.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return self if target.units == units
                          Severity: Major
                          Found in lib/ruby_units/unit.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return
                            Severity: Major
                            Found in lib/ruby_units/unit.rb - About 30 mins to fix

                              Method use_definition has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  def self.use_definition(definition)
                                    @unit_match_regex = nil # invalidate the unit match regex
                                    @temp_regex = nil # invalidate the temp regex
                                    if definition.prefix?
                                      prefix_values[definition.name] = definition.scalar
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb - About 25 mins 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

                              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

                              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 3 locations. Consider refactoring.
                              Open

                                    if (match = unit_string.match(FEET_INCH_REGEX))
                                      feet = Integer(match[:feet])
                                      inches = match[:inches]
                                      result = if feet.negative?
                                                 self.class.new("#{feet} ft") - self.class.new("#{inches} inches")
                              Severity: Major
                              Found in lib/ruby_units/unit.rb and 2 other locations - About 1 hr to fix
                              lib/ruby_units/unit.rb on lines 1705..1715
                              lib/ruby_units/unit.rb on lines 1718..1728

                              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 52.

                              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 3 locations. Consider refactoring.
                              Open

                                    if (match = unit_string.match(LBS_OZ_REGEX))
                                      pounds = Integer(match[:pounds])
                                      oz = match[:oz]
                                      result = if pounds.negative?
                                                 self.class.new("#{pounds} lbs") - self.class.new("#{oz} oz")
                              Severity: Major
                              Found in lib/ruby_units/unit.rb and 2 other locations - About 1 hr to fix
                              lib/ruby_units/unit.rb on lines 1692..1702
                              lib/ruby_units/unit.rb on lines 1718..1728

                              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 52.

                              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 3 locations. Consider refactoring.
                              Open

                                    if (match = unit_string.match(STONE_LB_REGEX))
                                      stone = Integer(match[:stone])
                                      pounds = match[:pounds]
                                      result = if stone.negative?
                                                 self.class.new("#{stone} stone") - self.class.new("#{pounds} lbs")
                              Severity: Major
                              Found in lib/ruby_units/unit.rb and 2 other locations - About 1 hr to fix
                              lib/ruby_units/unit.rb on lines 1692..1702
                              lib/ruby_units/unit.rb on lines 1705..1715

                              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 52.

                              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

                                    when :lbs
                                      pounds, ounces = convert_to("oz").scalar.abs.divmod(16)
                                      improper, frac = ounces.divmod(1)
                                      frac = frac.zero? ? "" : "-#{frac.rationalize(precision)}"
                                      out  = "#{negative? ? '-' : nil}#{pounds}#{separator}lbs #{improper}#{frac}#{separator}oz"
                              Severity: Major
                              Found in lib/ruby_units/unit.rb and 1 other location - About 1 hr to fix
                              lib/ruby_units/unit.rb on lines 691..695

                              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 51.

                              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

                                    when :stone
                                      stone, pounds = convert_to("lbs").scalar.abs.divmod(14)
                                      improper, frac = pounds.divmod(1)
                                      frac = frac.zero? ? "" : "-#{frac.rationalize(precision)}"
                                      out = "#{negative? ? '-' : nil}#{stone}#{separator}stone #{improper}#{frac}#{separator}lbs"
                              Severity: Major
                              Found in lib/ruby_units/unit.rb and 1 other location - About 1 hr to fix
                              lib/ruby_units/unit.rb on lines 686..690

                              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 51.

                              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

                                    @denominator = @denominator.map do |item|
                                      self.class.prefix_map[item[0]] ? [self.class.prefix_map[item[0]], self.class.unit_map[item[1]]] : [self.class.unit_map[item[1]]]
                                    end.flatten.compact.delete_if(&:empty?)
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 45 mins to fix
                              lib/ruby_units/unit.rb on lines 1774..1776

                              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 41.

                              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 = @numerator.map do |item|
                                      self.class.prefix_map[item[0]] ? [self.class.prefix_map[item[0]], self.class.unit_map[item[1]]] : [self.class.unit_map[item[1]]]
                                    end.flatten.compact.delete_if(&:empty?)
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 45 mins to fix
                              lib/ruby_units/unit.rb on lines 1778..1780

                              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 41.

                              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

                                    unless num == UNITY_ARRAY
                                      definitions = num.map { self.class.definition(_1) }
                                      definitions.reject!(&:prefix?) unless with_prefix
                                      definitions = definitions.chunk_while { |definition, _| definition.prefix? }.to_a
                                      output_numerator = definitions.map { _1.map(&:display_name).join }
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 35 mins to fix
                              lib/ruby_units/unit.rb on lines 1289..1293

                              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 36.

                              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

                                    unless den == UNITY_ARRAY
                                      definitions = den.map { self.class.definition(_1) }
                                      definitions.reject!(&:prefix?) unless with_prefix
                                      definitions = definitions.chunk_while { |definition, _| definition.prefix? }.to_a
                                      output_denominator = definitions.map { _1.map(&:display_name).join }
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 35 mins to fix
                              lib/ruby_units/unit.rb on lines 1282..1286

                              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 36.

                              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.uniq.each do |item|
                                      x = num.find_all { _1 == item }.size
                                      r = ((x / n) * (n - 1)).to_int
                                      r.times { num.delete_at(num.index(item)) }
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 25 mins to fix
                              lib/ruby_units/unit.rb on lines 1109..1112

                              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 31.

                              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

                                    @denominator.uniq.each do |item|
                                      x = den.find_all { _1 == item }.size
                                      r = ((x / n) * (n - 1)).to_int
                                      r.times { den.delete_at(den.index(item)) }
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 25 mins to fix
                              lib/ruby_units/unit.rb on lines 1103..1106

                              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 31.

                              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

                                      numerator2   = target.numerator.map { self.class.prefix_values[_1] || _1 }.map { _1.is_a?(Numeric) ? _1 : self.class.unit_values[_1][:scalar] }.compact
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 20 mins to fix
                              lib/ruby_units/unit.rb on lines 1206..1206

                              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 27.

                              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

                                      denominator2 = target.denominator.map { self.class.prefix_values[_1] || _1 }.map { _1.is_a?(Numeric) ? _1 : self.class.unit_values[_1][:scalar] }.compact
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 20 mins to fix
                              lib/ruby_units/unit.rb on lines 1205..1205

                              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 27.

                              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

                                  def %(other)
                                    raise ArgumentError, "Incompatible Units ('#{self}' not compatible with '#{other}')" unless compatible_with?(other)
                              
                                    self.class.new(base_scalar % other.to_unit.base_scalar, to_base.units).convert_to(self)
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 15 mins to fix
                              lib/ruby_units/unit.rb on lines 988..991

                              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 26.

                              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

                                      denominator1 = @denominator.map { self.class.prefix_values[_1] || _1 }.map { _1.is_a?(Numeric) ? _1 : self.class.unit_values[_1][:scalar] }.compact
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 15 mins to fix
                              lib/ruby_units/unit.rb on lines 1203..1203

                              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 26.

                              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

                                  def remainder(other)
                                    raise ArgumentError, "Incompatible Units ('#{self}' not compatible with '#{other}')" unless compatible_with?(other)
                              
                                    self.class.new(base_scalar.remainder(other.to_unit.base_scalar), to_base.units).convert_to(self)
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 15 mins to fix
                              lib/ruby_units/unit.rb on lines 1010..1013

                              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 26.

                              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

                                      numerator1   = @numerator.map { self.class.prefix_values[_1] || _1 }.map { _1.is_a?(Numeric) ? _1 : self.class.unit_values[_1][:scalar] }.compact
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 15 mins to fix
                              lib/ruby_units/unit.rb on lines 1204..1204

                              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 26.

                              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

                                    on = output_numerator
                                         .uniq
                                         .map { [_1, output_numerator.count(_1)] }
                                         .map { |element, power| (element.to_s.strip + (power > 1 ? "^#{power}" : "")) }
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 15 mins to fix
                              lib/ruby_units/unit.rb on lines 1308..1311

                              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 25.

                              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

                                      od  = output_denominator
                                            .uniq
                                            .map { [_1, output_denominator.count(_1)] }
                                            .map { |element, power| (element.to_s.strip + (power > 1 ? "^#{power}" : "")) }
                              Severity: Minor
                              Found in lib/ruby_units/unit.rb and 1 other location - About 15 mins to fix
                              lib/ruby_units/unit.rb on lines 1296..1299

                              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 25.

                              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

                              There are no issues that match your filters.

                              Category
                              Status