@@ -55,8 +55,8 @@ class << self
5555 self . unit_values = { }
5656 @unit_regex = nil
5757 @unit_match_regex = nil
58- UNITY = "<1>"
59- UNITY_ARRAY = [ UNITY ] . freeze
58+ UNITY = "<1>"
59+ UNITY_ARRAY = [ UNITY ] . freeze
6060
6161 SIGN_REGEX = /(?:[+-])?/ # +, -, or nothing
6262
@@ -75,36 +75,36 @@ class << self
7575 # and 'inches', but they aren't defined at the point in the code where we
7676 # need this regex.
7777 FEET_INCH_UNITS_REGEX = /(?:'|ft|feet)\s *(?<inches>#{ RATIONAL_NUMBER } |#{ SCI_NUMBER } )\s *(?:"|in|inch(?:es)?)/
78- FEET_INCH_REGEX = /(?<feet>#{ INTEGER_REGEX } )\s *#{ FEET_INCH_UNITS_REGEX } /
78+ FEET_INCH_REGEX = /(?<feet>#{ INTEGER_REGEX } )\s *#{ FEET_INCH_UNITS_REGEX } /
7979 # ideally we would like to generate this regex from the alias for a 'pound'
8080 # and 'ounce', but they aren't defined at the point in the code where we
8181 # need this regex.
82- LBS_OZ_UNIT_REGEX = /(?:#|lbs?|pounds?|pound-mass)+[\s ,]*(?<oz>#{ RATIONAL_NUMBER } |#{ UNSIGNED_INTEGER_REGEX } )\s *(?:ozs?|ounces?)/
83- LBS_OZ_REGEX = /(?<pounds>#{ INTEGER_REGEX } )\s *#{ LBS_OZ_UNIT_REGEX } /
82+ LBS_OZ_UNIT_REGEX = /(?:#|lbs?|pounds?|pound-mass)+[\s ,]*(?<oz>#{ RATIONAL_NUMBER } |#{ UNSIGNED_INTEGER_REGEX } )\s *(?:ozs?|ounces?)/
83+ LBS_OZ_REGEX = /(?<pounds>#{ INTEGER_REGEX } )\s *#{ LBS_OZ_UNIT_REGEX } /
8484 # ideally we would like to generate this regex from the alias for a 'stone'
8585 # and 'pound', but they aren't defined at the point in the code where we
8686 # need this regex. also note that the plural of 'stone' is still 'stone',
8787 # but we accept 'stones' anyway.
8888 STONE_LB_UNIT_REGEX = /(?:sts?|stones?)+[\s ,]*(?<pounds>#{ RATIONAL_NUMBER } |#{ UNSIGNED_INTEGER_REGEX } )\s *(?:#|lbs?|pounds?|pound-mass)*/
89- STONE_LB_REGEX = /(?<stone>#{ INTEGER_REGEX } )\s *#{ STONE_LB_UNIT_REGEX } /
89+ STONE_LB_REGEX = /(?<stone>#{ INTEGER_REGEX } )\s *#{ STONE_LB_UNIT_REGEX } /
9090 # Time formats: 12:34:56,78, (hh:mm:ss,msec) etc.
91- TIME_REGEX = /(?<hour>\d +):(?<min>\d +):?(?:(?<sec>\d +))?(?:[.](?<msec>\d +))?/
91+ TIME_REGEX = /(?<hour>\d +):(?<min>\d +):?(?:(?<sec>\d +))?(?:[.](?<msec>\d +))?/
9292 # Complex numbers: 1+2i, 1.0+2.0i, -1-1i, etc.
93- COMPLEX_NUMBER = /(?<real>#{ SCI_NUMBER } )?(?<imaginary>#{ SCI_NUMBER } )i\b /
93+ COMPLEX_NUMBER = /(?<real>#{ SCI_NUMBER } )?(?<imaginary>#{ SCI_NUMBER } )i\b /
9494 # Any Complex, Rational, or scientific number
95- ANY_NUMBER = /(#{ COMPLEX_NUMBER } |#{ RATIONAL_NUMBER } |#{ SCI_NUMBER } )/
96- ANY_NUMBER_REGEX = /(?:#{ ANY_NUMBER } )?\s ?([^-\d .].*)?/
97- NUMBER_REGEX = /(?<scalar>#{ SCI_NUMBER } *)\s *(?<unit>.+)?/ # a number followed by a unit
98- UNIT_STRING_REGEX = %r{#{ SCI_NUMBER } *\s *([^/]*)/*(.+)*}
99- TOP_REGEX = /(?<unit_part>[^ *]+)(?:\^ |\* \* )(?<exponent>[\d -]+)/
100- BOTTOM_REGEX = /(?<unit_part>[^* ]+)(?:\^ |\* \* )(?<exponent>\d +)/
101- NUMBER_UNIT_REGEX = /#{ SCI_NUMBER } ?(.*)/
102- COMPLEX_REGEX = /#{ COMPLEX_NUMBER } \s ?(?<unit>.+)?/
103- RATIONAL_REGEX = /#{ RATIONAL_NUMBER } \s ?(?<unit>.+)?/
104- KELVIN = [ "<kelvin>" ] . freeze
105- FAHRENHEIT = [ "<fahrenheit>" ] . freeze
106- RANKINE = [ "<rankine>" ] . freeze
107- CELSIUS = [ "<celsius>" ] . freeze
95+ ANY_NUMBER = /(#{ COMPLEX_NUMBER } |#{ RATIONAL_NUMBER } |#{ SCI_NUMBER } )/
96+ ANY_NUMBER_REGEX = /(?:#{ ANY_NUMBER } )?\s ?([^-\d .].*)?/
97+ NUMBER_REGEX = /(?<scalar>#{ SCI_NUMBER } *)\s *(?<unit>.+)?/ # a number followed by a unit
98+ UNIT_STRING_REGEX = %r{#{ SCI_NUMBER } *\s *([^/]*)/*(.+)*}
99+ TOP_REGEX = /(?<unit_part>[^ *]+)(?:\^ |\* \* )(?<exponent>[\d -]+)/
100+ BOTTOM_REGEX = /(?<unit_part>[^* ]+)(?:\^ |\* \* )(?<exponent>\d +)/
101+ NUMBER_UNIT_REGEX = /#{ SCI_NUMBER } ?(.*)/
102+ COMPLEX_REGEX = /#{ COMPLEX_NUMBER } \s ?(?<unit>.+)?/
103+ RATIONAL_REGEX = /#{ RATIONAL_NUMBER } \s ?(?<unit>.+)?/
104+ KELVIN = [ "<kelvin>" ] . freeze
105+ FAHRENHEIT = [ "<fahrenheit>" ] . freeze
106+ RANKINE = [ "<rankine>" ] . freeze
107+ CELSIUS = [ "<celsius>" ] . freeze
108108
109109 # Temperature conversion constants
110110 CELSIUS_OFFSET_TO_KELVIN = 273.15 # offset to convert Celsius to Kelvin
@@ -1229,9 +1229,9 @@ def convert_to(other)
12291229
12301230 target_num = target . numerator
12311231 target_den = target . denominator
1232- source_numerator_values = to_scalar . call ( @numerator )
1232+ source_numerator_values = to_scalar . call ( @numerator )
12331233 source_denominator_values = to_scalar . call ( @denominator )
1234- target_numerator_values = to_scalar . call ( target_num )
1234+ target_numerator_values = to_scalar . call ( target_num )
12351235 target_denominator_values = to_scalar . call ( target_den )
12361236 # @type [Rational, Numeric]
12371237 scalar_is_integer = @scalar . is_a? ( Integer )
@@ -1295,10 +1295,10 @@ def as_json(*)
12951295 def units ( with_prefix : true , format : nil )
12961296 return "" if @numerator == UNITY_ARRAY && @denominator == UNITY_ARRAY
12971297
1298- output_numerator = [ "1" ]
1298+ output_numerator = [ "1" ]
12991299 output_denominator = [ ]
1300- num = @numerator . clone . compact
1301- den = @denominator . clone . compact
1300+ num = @numerator . clone . compact
1301+ den = @denominator . clone . compact
13021302
13031303 process_unit_array = lambda do |unit_array |
13041304 definitions = unit_array . map { unit_class . definition ( _1 ) }
@@ -1605,11 +1605,11 @@ def apply_signature_items(vector, items, sign)
16051605 def update_base_scalar
16061606 if base?
16071607 @base_scalar = @scalar
1608- @signature = unit_signature
1608+ @signature = unit_signature
16091609 else
1610- base = to_base
1610+ base = to_base
16111611 @base_scalar = base . scalar
1612- @signature = base . signature
1612+ @signature = base . signature
16131613 end
16141614 end
16151615
@@ -2103,7 +2103,7 @@ def parse(passed_unit_string = "0")
21032103
21042104 if unit
21052105 copy ( unit )
2106- @scalar *= mult
2106+ @scalar *= mult
21072107 @base_scalar *= mult
21082108 return self
21092109 end
@@ -2199,7 +2199,7 @@ def parse(passed_unit_string = "0")
21992199
22002200 @scalar /= bottom_scalar
22012201
2202- @numerator ||= UNITY_ARRAY
2202+ @numerator ||= UNITY_ARRAY
22032203 @denominator ||= UNITY_ARRAY
22042204 @numerator = top . scan ( unit_match_regex ) . delete_if ( &:empty? ) . compact if top
22052205 @denominator = bottom . scan ( unit_match_regex ) . delete_if ( &:empty? ) . compact if bottom
0 commit comments