@@ -180,7 +180,7 @@ def self.inherited(subclass)
180180
181181 # setup internal arrays and hashes
182182 # @return [Boolean]
183- def self . setup
183+ def self . setup # rubocop:disable Naming/PredicateMethod
184184 clear_cache
185185 self . prefix_values = { }
186186 self . prefix_map = { }
@@ -275,7 +275,7 @@ def self.cached
275275 end
276276
277277 # @return [Boolean]
278- def self . clear_cache
278+ def self . clear_cache # rubocop:disable Naming/PredicateMethod
279279 cached . clear
280280 base_unit_cache . clear
281281 new ( 1 )
@@ -556,7 +556,7 @@ def initialize(*options)
556556 _opt_scalar , opt_units = self . class . parse_into_numbers_and_units ( options [ 0 ] )
557557 if !( self . class . cached . keys . include? ( opt_units ) ||
558558 ( opt_units =~ %r{\D /[\d +.]+} ) ||
559- ( opt_units =~ %r{(#{ self . class . temp_regex } )|(#{ STONE_LB_UNIT_REGEX } )|(#{ LBS_OZ_UNIT_REGEX } )|(#{ FEET_INCH_UNITS_REGEX } )|%|(#{ TIME_REGEX } )|i\s ?(.+)?|±|\+ /-} ) ) && ( opt_units && !opt_units . empty? )
559+ ( opt_units =~ %r{(#{ self . class . temp_regex } )|(#{ STONE_LB_UNIT_REGEX } )|(#{ LBS_OZ_UNIT_REGEX } )|(#{ FEET_INCH_UNITS_REGEX } )|%|(#{ TIME_REGEX } )|i\s ?(.+)?|±|\+ /-} ) ) && opt_units && !opt_units . empty?
560560 self . class . cached . set ( opt_units , scalar == 1 ? self : opt_units . to_unit )
561561 end
562562 end
@@ -682,17 +682,17 @@ def to_s(target_units = nil, precision: 0.0001, format: RubyUnits.configuration.
682682 feet , inches = convert_to ( "in" ) . scalar . abs . divmod ( 12 )
683683 improper , frac = inches . divmod ( 1 )
684684 frac = frac . zero? ? "" : "-#{ frac . rationalize ( precision ) } "
685- out = "#{ negative? ? '-' : nil } #{ feet } '#{ improper } #{ frac } \" "
685+ out = "#{ '-' if negative? } #{ feet } '#{ improper } #{ frac } \" "
686686 when :lbs
687687 pounds , ounces = convert_to ( "oz" ) . scalar . abs . divmod ( 16 )
688688 improper , frac = ounces . divmod ( 1 )
689689 frac = frac . zero? ? "" : "-#{ frac . rationalize ( precision ) } "
690- out = "#{ negative? ? '-' : nil } #{ pounds } #{ separator } lbs #{ improper } #{ frac } #{ separator } oz"
690+ out = "#{ '-' if negative? } #{ pounds } #{ separator } lbs #{ improper } #{ frac } #{ separator } oz"
691691 when :stone
692692 stone , pounds = convert_to ( "lbs" ) . scalar . abs . divmod ( 14 )
693693 improper , frac = pounds . divmod ( 1 )
694694 frac = frac . zero? ? "" : "-#{ frac . rationalize ( precision ) } "
695- out = "#{ negative? ? '-' : nil } #{ stone } #{ separator } stone #{ improper } #{ frac } #{ separator } lbs"
695+ out = "#{ '-' if negative? } #{ stone } #{ separator } stone #{ improper } #{ frac } #{ separator } lbs"
696696 when String
697697 out = case target_units . strip
698698 when /\A \s *\Z / # whitespace only
@@ -1309,7 +1309,7 @@ def units(with_prefix: true, format: nil)
13091309 . uniq
13101310 . map { [ _1 , output_denominator . count ( _1 ) ] }
13111311 . map { |element , power | ( element . to_s . strip + ( power > 1 ? "^#{ power } " : "" ) ) }
1312- "#{ on . join ( '*' ) } #{ od . empty? ? '' : "/#{ od . join ( '*' ) } " } " . strip
1312+ "#{ on . join ( '*' ) } #{ "/#{ od . join ( '*' ) } " unless od . empty? } " . strip
13131313 end
13141314 end
13151315
@@ -1768,7 +1768,7 @@ def parse(passed_unit_string = "0")
17681768
17691769 # eliminate all known terms from this string. This is a quick check to see if the passed unit
17701770 # contains terms that are not defined.
1771- used = "#{ top } #{ bottom } " . to_s . gsub ( self . class . unit_match_regex , "" ) . gsub ( %r{[\d *, "'_^/$]} , "" )
1771+ used = "#{ top } #{ bottom } " . gsub ( self . class . unit_match_regex , "" ) . gsub ( %r{[\d *, "'_^/$]} , "" )
17721772 raise ( ArgumentError , "'#{ passed_unit_string } ' Unit not recognized" ) unless used . empty?
17731773
17741774 @numerator = @numerator . map do |item |
0 commit comments