numscaler 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +124 -62
- data/examples/esoteric.rb +21 -0
- data/examples/graphing.rb +13 -0
- data/examples/units.rb +36 -0
- data/lib/numscaler.rb +14 -10
- data/numscaler.gemspec +2 -0
- data/spec/numscaler_spec.rb +116 -107
- metadata +6 -4
- data/.rspec +0 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7be33f9f41d6a311789c24901c46e282f44577ba
         | 
| 4 | 
            +
              data.tar.gz: 14dfbe2d52b7a4535ebc56b1533c0b4fc8877e39
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7fc1433ded6360e54fb7555c19928baa30e89a117b79d31b612ffe60100a919610cc0915ccf8b4b2940c80dd13da890846cbdfcabf87056b68417dac2ba3e23b
         | 
| 7 | 
            +
              data.tar.gz: c09f9d90aac10634875d0318ddb3737cab03fbbfea976d918289c2006f81889d33a916e310a5d0ec48ca75ed152951d7827919ee2a66969b0cf4441715e25092
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -29,73 +29,135 @@ and therefore that is the default rounding. | |
| 29 29 |  | 
| 30 30 | 
             
            There is a pretty brute-force test suite. Should work with any Ruby version.
         | 
| 31 31 |  | 
| 32 | 
            +
            ## Applications
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              * Scaling when graphing
         | 
| 35 | 
            +
                ...from `0.0..1.0` to `0..(height-1)`
         | 
| 36 | 
            +
              * Bounded unit conversion
         | 
| 37 | 
            +
                ...from Celsius to Fahrenheit, Centimeters to Inches
         | 
| 38 | 
            +
              * Circular unit conversion
         | 
| 39 | 
            +
                ...from degrees to radians
         | 
| 40 | 
            +
              * Value to index mapping
         | 
| 41 | 
            +
                ...from `0.0..1.0` to 'very bad' - 'very good'
         | 
| 42 | 
            +
             | 
| 32 43 | 
             
            ## Examples
         | 
| 33 44 |  | 
| 34 | 
            -
            Install | 
| 45 | 
            +
            Install:
         | 
| 35 46 |  | 
| 36 47 | 
             
                $ gem install numscaler
         | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
                 | 
| 42 | 
            -
                 | 
| 43 | 
            -
                 | 
| 44 | 
            -
                 | 
| 45 | 
            -
                 | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
                 | 
| 51 | 
            -
                 | 
| 52 | 
            -
                 | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
                 | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
                 | 
| 71 | 
            -
                 | 
| 72 | 
            -
                 | 
| 73 | 
            -
                 | 
| 74 | 
            -
                 | 
| 75 | 
            -
                 | 
| 76 | 
            -
                [ | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
                 | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
                 | 
| 85 | 
            -
                 | 
| 86 | 
            -
                 | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 48 | 
            +
             | 
| 49 | 
            +
            From the `examples/` directory, first some graphing:
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                require 'numscaler'
         | 
| 52 | 
            +
                
         | 
| 53 | 
            +
                s1 = NumScaler.new(0..64, 0.0..Math::PI*2.0)
         | 
| 54 | 
            +
                s2 = NumScaler.new(-1.0..1.0, 0..9)
         | 
| 55 | 
            +
                
         | 
| 56 | 
            +
                graph = (0..64).to_a.collect do |e|
         | 
| 57 | 
            +
                  i = s2.from(Math.sin(s1.from(e)))
         | 
| 58 | 
            +
                  a = [' '] * 10
         | 
| 59 | 
            +
                  a[i] = '#'
         | 
| 60 | 
            +
                  a
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
                
         | 
| 63 | 
            +
                puts graph.transpose.collect {|e| e.join }
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            Running it will produce a lovely:
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                                                            #########            
         | 
| 68 | 
            +
                                                        ####         ####        
         | 
| 69 | 
            +
                                                     ###                 ###     
         | 
| 70 | 
            +
                                                   ##                       ##   
         | 
| 71 | 
            +
                                                 ##                           ## 
         | 
| 72 | 
            +
                ###                           ###                               #
         | 
| 73 | 
            +
                   ##                       ##                                   
         | 
| 74 | 
            +
                     ###                 ###                                     
         | 
| 75 | 
            +
                        ####         ####                                        
         | 
| 76 | 
            +
                            #########                                            
         | 
| 77 | 
            +
             | 
| 78 | 
            +
            You can also use it for unit conversion if you wish, like so:
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                require 'numscaler'
         | 
| 81 | 
            +
                
         | 
| 82 | 
            +
                distance = NumScaler.new(0.0..100.0, 0.0..39.3701)
         | 
| 83 | 
            +
                temperature = NumScaler.new(-30.0..120.0, -22.0..248.0)
         | 
| 84 | 
            +
                angle = NumScaler.new(0.0..90.0, 0.0..Math::PI/2.0)
         | 
| 85 | 
            +
                
         | 
| 86 | 
            +
                puts 'Distance:'
         | 
| 87 | 
            +
                [
         | 
| 88 | 
            +
                  ['9 mm ammo', 0.9],
         | 
| 89 | 
            +
                  ['max pin distance in an europlug', 1.86],
         | 
| 90 | 
            +
                  ['average baguette length', 65.0],
         | 
| 91 | 
            +
                ].each do |label, cm|
         | 
| 92 | 
            +
                  print "#{label} (#{cm} cm) is ".rjust(50)
         | 
| 93 | 
            +
                  puts distance.from(cm).to_s + ' inch'
         | 
| 94 | 
            +
                end
         | 
| 95 | 
            +
                
         | 
| 96 | 
            +
                puts "\nTemperature:"
         | 
| 97 | 
            +
                [
         | 
| 98 | 
            +
                  ['siberian cold', -25.0],
         | 
| 99 | 
            +
                  ['minimal workplace temp', 18.0],
         | 
| 100 | 
            +
                  ['usually comfortable', 25.0],
         | 
| 101 | 
            +
                  ['Polish summer', 35.0],
         | 
| 102 | 
            +
                ].each do |label, cent|
         | 
| 103 | 
            +
                  print "#{label} (#{cent} Celsius) is ".rjust(50)
         | 
| 104 | 
            +
                  puts temperature.from(cent).to_s + ' Fahrenheit'
         | 
| 105 | 
            +
                end
         | 
| 106 | 
            +
                
         | 
| 107 | 
            +
                puts "\nAngle:"
         | 
| 108 | 
            +
                [
         | 
| 109 | 
            +
                  ['human FOV blind spot width', 5.5],
         | 
| 110 | 
            +
                  ['decent slope', 23.0],
         | 
| 111 | 
            +
                  ['in the corner', 90.0],
         | 
| 112 | 
            +
                ].each do |label, deg|
         | 
| 113 | 
            +
                  print "#{label} (#{deg} degrees) is ".rjust(50)
         | 
| 114 | 
            +
                  puts angle.from(deg).to_s + ' radians'
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            Which will produce:
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                Distance:
         | 
| 120 | 
            +
                                            9 mm ammo (0.9 cm) is 0.3543309 inch
         | 
| 121 | 
            +
                      max pin distance in a europlug (1.86 cm) is 0.73228386 inch
         | 
| 122 | 
            +
                             average baguette length (65.0 cm) is 25.590565 inch
         | 
| 123 | 
            +
                
         | 
| 124 | 
            +
                Temperature:
         | 
| 125 | 
            +
                                 siberian cold (-25.0 Celsius) is -13.0 Fahrenheit
         | 
| 126 | 
            +
                         minimal workplace temp (18.0 Celsius) is 64.4 Fahrenheit
         | 
| 127 | 
            +
                            usually comfortable (25.0 Celsius) is 77.0 Fahrenheit
         | 
| 128 | 
            +
                                  Polish summer (35.0 Celsius) is 95.0 Fahrenheit
         | 
| 129 | 
            +
                
         | 
| 130 | 
            +
                Angle:
         | 
| 131 | 
            +
                      human FOV blind spot width (5.5 degrees) is 0.09599310885969 radians
         | 
| 132 | 
            +
                                   decent slope (23.0 degrees) is 0.4014257279587 radians
         | 
| 133 | 
            +
                                  in the corner (90.0 degrees) is 1.5707963267949 radians
         | 
| 134 | 
            +
             | 
| 135 | 
            +
            You can also do some esoteric stuff, like:
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                require 'numscaler'
         | 
| 138 | 
            +
                
         | 
| 139 | 
            +
                palette = ' ,-\'"\\O/"\'-. '.split('')
         | 
| 140 | 
            +
                s = NumScaler.new(-1.0..1.0, 0..(palette.length - 1), :mode => :cycle)
         | 
| 141 | 
            +
                c = NumScaler.new(1..32, 0.0..Math::PI*2.0, :mode => :cycle)
         | 
| 91 142 |  | 
| 92 | 
            -
                 | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 143 | 
            +
                1.upto(256) do |o|
         | 
| 144 | 
            +
                  puts "\e[H\e[2J"
         | 
| 145 | 
            +
                  1.upto(32) do |y|
         | 
| 146 | 
            +
                    1.upto(64) do |x|
         | 
| 147 | 
            +
                      print palette[s.from(
         | 
| 148 | 
            +
                        Math.tan(c.from(o)) *\
         | 
| 149 | 
            +
                        (Math.sin(c.from(x)) +\
         | 
| 150 | 
            +
                        Math.cos(c.from(y)))
         | 
| 151 | 
            +
                      )]
         | 
| 152 | 
            +
                    end
         | 
| 153 | 
            +
                    print "\n"
         | 
| 154 | 
            +
                  end
         | 
| 155 | 
            +
                  print "\n"
         | 
| 156 | 
            +
                  sleep(0.5)
         | 
| 157 | 
            +
                end
         | 
| 158 | 
            +
             | 
| 159 | 
            +
            For this you'd have to run it in a terminal (and it will probably not work
         | 
| 160 | 
            +
            as intended on windows).
         | 
| 99 161 |  | 
| 100 162 | 
             
            ## Copyright
         | 
| 101 163 |  | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'numscaler'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            palette = ' ,-\'"\\O/"\'-. '.split('')
         | 
| 4 | 
            +
            s = NumScaler.new(-1.0..1.0, 0..(palette.length - 1), :mode => :cycle)
         | 
| 5 | 
            +
            c = NumScaler.new(1..32, 0.0..Math::PI*2.0, :mode => :cycle)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            1.upto(256) do |o|
         | 
| 8 | 
            +
              puts "\e[H\e[2J"
         | 
| 9 | 
            +
              1.upto(32) do |y|
         | 
| 10 | 
            +
                1.upto(64) do |x|
         | 
| 11 | 
            +
                  print palette[s.from(
         | 
| 12 | 
            +
                    Math.tan(c.from(o)) *\
         | 
| 13 | 
            +
                    (Math.sin(c.from(x)) +\
         | 
| 14 | 
            +
                    Math.cos(c.from(y)))
         | 
| 15 | 
            +
                  )]
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
                print "\n"
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
              print "\n"
         | 
| 20 | 
            +
              sleep(0.5)
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require 'numscaler'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            s1 = NumScaler.new(0..64, 0.0..Math::PI*2.0)
         | 
| 4 | 
            +
            s2 = NumScaler.new(-1.0..1.0, 0..9)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            graph = (0..64).to_a.collect do |e|
         | 
| 7 | 
            +
              i = s2.from(Math.sin(s1.from(e)))
         | 
| 8 | 
            +
              a = [' '] * 10
         | 
| 9 | 
            +
              a[i] = '#'
         | 
| 10 | 
            +
              a
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            puts graph.transpose.collect {|e| e.join }
         | 
    
        data/examples/units.rb
    ADDED
    
    | @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            require 'numscaler'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            distance = NumScaler.new(0.0..100.0, 0.0..39.3701)
         | 
| 4 | 
            +
            temperature = NumScaler.new(-30.0..120.0, -22.0..248.0)
         | 
| 5 | 
            +
            angle = NumScaler.new(0.0..90.0, 0.0..Math::PI/2.0)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            puts 'Distance:'
         | 
| 8 | 
            +
            [
         | 
| 9 | 
            +
              ['9 mm ammo', 0.9],
         | 
| 10 | 
            +
              ['max pin distance in an europlug', 1.86],
         | 
| 11 | 
            +
              ['average baguette length', 65.0],
         | 
| 12 | 
            +
            ].each do |label, cm|
         | 
| 13 | 
            +
              print "#{label} (#{cm} cm) is ".rjust(50)
         | 
| 14 | 
            +
              puts distance.from(cm).to_s + ' inch'
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            puts "\nTemperature:"
         | 
| 18 | 
            +
            [
         | 
| 19 | 
            +
              ['siberian cold', -25.0],
         | 
| 20 | 
            +
              ['minimal workplace temp', 18.0],
         | 
| 21 | 
            +
              ['usually comfortable', 25.0],
         | 
| 22 | 
            +
              ['Polish summer', 35.0],
         | 
| 23 | 
            +
            ].each do |label, cent|
         | 
| 24 | 
            +
              print "#{label} (#{cent} Celsius) is ".rjust(50)
         | 
| 25 | 
            +
              puts temperature.from(cent).to_s + ' Fahrenheit'
         | 
| 26 | 
            +
            end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            puts "\nAngle:"
         | 
| 29 | 
            +
            [
         | 
| 30 | 
            +
              ['human FOV blind spot width', 5.5],
         | 
| 31 | 
            +
              ['decent slope', 23.0],
         | 
| 32 | 
            +
              ['in the corner', 90.0],
         | 
| 33 | 
            +
            ].each do |label, deg|
         | 
| 34 | 
            +
              print "#{label} (#{deg} degrees) is ".rjust(50)
         | 
| 35 | 
            +
              puts angle.from(deg).to_s + ' radians'
         | 
| 36 | 
            +
            end
         | 
    
        data/lib/numscaler.rb
    CHANGED
    
    | @@ -3,30 +3,34 @@ | |
| 3 3 | 
             
            # See {file:README.md} for practical examples.
         | 
| 4 4 | 
             
            class NumScaler
         | 
| 5 5 | 
             
              # NumScaler version string
         | 
| 6 | 
            -
              VERSION = '0.0. | 
| 6 | 
            +
              VERSION = '0.0.5'
         | 
| 7 7 | 
             
              # Epsilon defines rounding precision
         | 
| 8 8 | 
             
              EPSILON = 14
         | 
| 9 9 | 
             
              # Available clamping modes
         | 
| 10 10 | 
             
              MODES = [:strict, :cycle, :clamp]
         | 
| 11 11 |  | 
| 12 | 
            +
              # Additional `options`:
         | 
| 13 | 
            +
              #
         | 
| 14 | 
            +
              #   * `:mode` - specify clamping mode (*default: `:strict`*)
         | 
| 15 | 
            +
              #   * `:precision` - specify Float rounding (*default: `EPSILON`*)
         | 
| 16 | 
            +
              #
         | 
| 17 | 
            +
              # Precision defines number of significant decimal digits for rounding.
         | 
| 18 | 
            +
              #
         | 
| 12 19 | 
             
              # Current clamping modes:
         | 
| 13 20 | 
             
              #
         | 
| 14 21 | 
             
              #   * `:strict` - raise ArgumentError for out-of-range number (*default*)
         | 
| 15 22 | 
             
              #   * `:clamp`  - clamp number to source range
         | 
| 16 23 | 
             
              #   * `:cycle`  - treat range as a circle of values
         | 
| 17 24 | 
             
              #
         | 
| 18 | 
            -
              # Precision defines number of significant decimal digits for rounding.
         | 
| 19 | 
            -
              #
         | 
| 20 25 | 
             
              # @param from [Range] source range
         | 
| 21 26 | 
             
              # @param to [Range] target range
         | 
| 22 | 
            -
              # @param  | 
| 23 | 
            -
               | 
| 24 | 
            -
             | 
| 25 | 
            -
                 | 
| 26 | 
            -
                raise ArgumentError, 'Precision out of ranger' unless precision > 0
         | 
| 27 | 
            +
              # @param options [Hash] additional options
         | 
| 28 | 
            +
              def initialize(from, to, options = {})
         | 
| 29 | 
            +
                @mode = options[:mode] || MODES.first
         | 
| 30 | 
            +
                @prec = options[:precision] || EPSILON
         | 
| 27 31 |  | 
| 28 | 
            -
                 | 
| 29 | 
            -
                @prec  | 
| 32 | 
            +
                raise ArgumentError, 'Unknown mode' unless MODES.member? @mode
         | 
| 33 | 
            +
                raise ArgumentError, 'Precision out of range' unless @prec > 0
         | 
| 30 34 |  | 
| 31 35 | 
             
                @src = { :orig  => from.min,
         | 
| 32 36 | 
             
                         :range => from.max.to_f - from.min.to_f,
         | 
    
        data/numscaler.gemspec
    CHANGED
    
    | @@ -18,6 +18,8 @@ Gem::Specification.new do |gem| | |
| 18 18 | 
             
              gem.test_files    = gem.files.grep(%r{^spec/})
         | 
| 19 19 | 
             
              gem.require_paths = ['lib']
         | 
| 20 20 |  | 
| 21 | 
            +
              gem.required_ruby_version = '>= 1.8.7'
         | 
| 22 | 
            +
             | 
| 21 23 | 
             
              gem.add_development_dependency 'rspec', '~> 2.4'
         | 
| 22 24 | 
             
              gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
         | 
| 23 25 | 
             
              gem.add_development_dependency 'yard', '~> 0.8'
         | 
    
        data/spec/numscaler_spec.rb
    CHANGED
    
    | @@ -3,40 +3,49 @@ | |
| 3 3 | 
             
            require 'rspec'
         | 
| 4 4 | 
             
            require 'numscaler'
         | 
| 5 5 |  | 
| 6 | 
            +
            RSpec.configure do |c|
         | 
| 7 | 
            +
              c.expect_with :rspec do |cc|
         | 
| 8 | 
            +
                cc.syntax = :expect
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 6 12 | 
             
            describe NumScaler do
         | 
| 7 13 | 
             
              it 'should have a VERSION constant' do
         | 
| 8 | 
            -
                NumScaler::VERSION. | 
| 14 | 
            +
                expect(NumScaler::VERSION).to_not be_empty
         | 
| 9 15 | 
             
              end
         | 
| 10 16 |  | 
| 11 17 | 
             
              it 'should have an EPSILON constant' do
         | 
| 12 | 
            -
                NumScaler::EPSILON. | 
| 18 | 
            +
                expect(NumScaler::EPSILON).to be > 0
         | 
| 13 19 | 
             
              end
         | 
| 14 20 |  | 
| 15 21 | 
             
              it 'should define clamping MODES' do
         | 
| 16 | 
            -
                NumScaler::MODES. | 
| 22 | 
            +
                expect(NumScaler::MODES).to_not be_empty
         | 
| 17 23 | 
             
              end
         | 
| 18 24 |  | 
| 19 25 | 
             
              it 'should check arguments' do
         | 
| 20 | 
            -
                 | 
| 21 | 
            -
                  NumScaler.new(1..8, 16..32, :nonext)
         | 
| 22 | 
            -
                }. | 
| 26 | 
            +
                expect {
         | 
| 27 | 
            +
                  NumScaler.new(1..8, 16..32, :mode => :nonext)
         | 
| 28 | 
            +
                }.to raise_error(ArgumentError)
         | 
| 29 | 
            +
                expect {
         | 
| 30 | 
            +
                  NumScaler.new(1..8, 16..32, :precision => 0)
         | 
| 31 | 
            +
                }.to raise_error(ArgumentError)
         | 
| 23 32 | 
             
              end
         | 
| 24 33 |  | 
| 25 34 | 
             
              context 'should work with Integer <=> Integer ranges and' do
         | 
| 26 35 | 
             
                it 'should convert from' do
         | 
| 27 | 
            -
                   | 
| 36 | 
            +
                  s = NumScaler.new(1..8, 16..32)
         | 
| 28 37 |  | 
| 29 | 
            -
                   | 
| 30 | 
            -
                   | 
| 31 | 
            -
                   | 
| 38 | 
            +
                  expect(s.from(1)).to eql 16
         | 
| 39 | 
            +
                  expect(s.from(4)).to eql 23
         | 
| 40 | 
            +
                  expect(s.from(8)).to eql 32
         | 
| 32 41 | 
             
                end
         | 
| 33 42 |  | 
| 34 43 | 
             
                it 'should convert to' do
         | 
| 35 | 
            -
                   | 
| 44 | 
            +
                  s = NumScaler.new(1..8, -32..32)
         | 
| 36 45 |  | 
| 37 | 
            -
                   | 
| 38 | 
            -
                   | 
| 39 | 
            -
                   | 
| 46 | 
            +
                  expect(s.to(-32)).to eql 1
         | 
| 47 | 
            +
                  expect(s.to(  0)).to eql 5
         | 
| 48 | 
            +
                  expect(s.to( 32)).to eql 8
         | 
| 40 49 | 
             
                end
         | 
| 41 50 | 
             
              end
         | 
| 42 51 |  | 
| @@ -46,27 +55,27 @@ describe NumScaler do | |
| 46 55 | 
             
                end
         | 
| 47 56 |  | 
| 48 57 | 
             
                it 'should convert from' do
         | 
| 49 | 
            -
                   | 
| 50 | 
            -
                   | 
| 51 | 
            -
                   | 
| 52 | 
            -
                   | 
| 53 | 
            -
             | 
| 54 | 
            -
                   | 
| 55 | 
            -
                   | 
| 56 | 
            -
                   | 
| 57 | 
            -
                   | 
| 58 | 
            +
                  s = NumScaler.new(0..15, 0.0..Math::PI)
         | 
| 59 | 
            +
                  expect(s.from( 0  )).to eql 0.0
         | 
| 60 | 
            +
                  expect(s.from( 7.5)).to eql (Math::PI/2.0).round(@prec)
         | 
| 61 | 
            +
                  expect(s.from(15  )).to eql Math::PI.round(@prec)
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  s = NumScaler.new(-15..15, 0.0..Math::PI)
         | 
| 64 | 
            +
                  expect(s.from(-15)).to eql 0.0
         | 
| 65 | 
            +
                  expect(s.from(  0)).to eql (Math::PI/2.0).round(@prec)
         | 
| 66 | 
            +
                  expect(s.from( 15)).to eql Math::PI.round(@prec)
         | 
| 58 67 | 
             
                end
         | 
| 59 68 |  | 
| 60 69 | 
             
                it 'should convert to' do
         | 
| 61 | 
            -
                   | 
| 62 | 
            -
                   | 
| 63 | 
            -
                   | 
| 64 | 
            -
                   | 
| 65 | 
            -
             | 
| 66 | 
            -
                   | 
| 67 | 
            -
                   | 
| 68 | 
            -
                   | 
| 69 | 
            -
                   | 
| 70 | 
            +
                  s = NumScaler.new(0..15, 0.0..Math::PI)
         | 
| 71 | 
            +
                  expect(s.to(0.0)).to          eql  0
         | 
| 72 | 
            +
                  expect(s.to(Math::PI/2.0)).to eql  7
         | 
| 73 | 
            +
                  expect(s.to(Math::PI)).to     eql 15
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  s = NumScaler.new(-15..15, 0.0..Math::PI)
         | 
| 76 | 
            +
                  expect(s.to(0.0)).to          eql -15
         | 
| 77 | 
            +
                  expect(s.to(Math::PI/2.0)).to eql   0
         | 
| 78 | 
            +
                  expect(s.to(Math::PI)).to     eql  15
         | 
| 70 79 | 
             
                end
         | 
| 71 80 | 
             
              end
         | 
| 72 81 |  | 
| @@ -76,108 +85,108 @@ describe NumScaler do | |
| 76 85 | 
             
                end
         | 
| 77 86 |  | 
| 78 87 | 
             
                it 'should convert from' do
         | 
| 79 | 
            -
                   | 
| 80 | 
            -
                   | 
| 81 | 
            -
                   | 
| 82 | 
            -
                   | 
| 83 | 
            -
                   | 
| 84 | 
            -
                   | 
| 85 | 
            -
             | 
| 86 | 
            -
                   | 
| 87 | 
            -
                   | 
| 88 | 
            -
                   | 
| 89 | 
            -
                   | 
| 90 | 
            -
                   | 
| 91 | 
            -
                   | 
| 88 | 
            +
                  s = NumScaler.new(0.0..256.0, 0.0..Math::PI)
         | 
| 89 | 
            +
                  expect(s.from(  0.0)).to eql 0.0
         | 
| 90 | 
            +
                  expect(s.from( 32.0)).to eql (Math::PI/8.0).round(@prec)
         | 
| 91 | 
            +
                  expect(s.from( 64.0)).to eql (Math::PI/4.0).round(@prec)
         | 
| 92 | 
            +
                  expect(s.from(128.0)).to eql (Math::PI/2.0).round(@prec)
         | 
| 93 | 
            +
                  expect(s.from(256.0)).to eql Math::PI.round(@prec)
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                  s = NumScaler.new(0.0..256.0, -Math::PI..Math::PI)
         | 
| 96 | 
            +
                  expect(s.from(  0.0)).to eql -Math::PI.round(@prec)
         | 
| 97 | 
            +
                  expect(s.from( 64.0)).to eql (-Math::PI/2.0).round(@prec)
         | 
| 98 | 
            +
                  expect(s.from(128.0)).to eql 0.0
         | 
| 99 | 
            +
                  expect(s.from(192.0)).to eql (Math::PI/2.0).round(@prec)
         | 
| 100 | 
            +
                  expect(s.from(256.0)).to eql Math::PI.round(@prec)
         | 
| 92 101 | 
             
                end
         | 
| 93 102 |  | 
| 94 103 | 
             
                it 'should convert to' do
         | 
| 95 | 
            -
                   | 
| 96 | 
            -
                   | 
| 97 | 
            -
                   | 
| 98 | 
            -
                   | 
| 99 | 
            -
                   | 
| 100 | 
            -
                   | 
| 101 | 
            -
             | 
| 102 | 
            -
                   | 
| 103 | 
            -
                   | 
| 104 | 
            -
                   | 
| 105 | 
            -
                   | 
| 106 | 
            -
                   | 
| 107 | 
            -
                   | 
| 104 | 
            +
                  s = NumScaler.new(0.0..256.0, 0.0..Math::PI)
         | 
| 105 | 
            +
                  expect(s.to(0.0)).to          eql   0.0
         | 
| 106 | 
            +
                  expect(s.to(Math::PI/8.0)).to eql  32.0
         | 
| 107 | 
            +
                  expect(s.to(Math::PI/4.0)).to eql  64.0
         | 
| 108 | 
            +
                  expect(s.to(Math::PI/2.0)).to eql 128.0
         | 
| 109 | 
            +
                  expect(s.to(Math::PI)).to     eql 256.0
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                  s = NumScaler.new(0.0..256.0, -Math::PI..Math::PI)
         | 
| 112 | 
            +
                  expect(s.to(-Math::PI)).to     eql   0.0
         | 
| 113 | 
            +
                  expect(s.to(-Math::PI/2.0)).to eql  64.0
         | 
| 114 | 
            +
                  expect(s.to(0.0)).to           eql 128.0
         | 
| 115 | 
            +
                  expect(s.to(Math::PI/2.0)).to  eql 192.0
         | 
| 116 | 
            +
                  expect(s.to(Math::PI)).to      eql 256.0
         | 
| 108 117 | 
             
                end
         | 
| 109 118 | 
             
              end
         | 
| 110 119 |  | 
| 111 120 | 
             
              context 'should :strict clamp properly' do
         | 
| 112 121 | 
             
                it 'with Integer ranges' do
         | 
| 113 | 
            -
                   | 
| 114 | 
            -
                   | 
| 115 | 
            -
                   | 
| 116 | 
            -
                   | 
| 117 | 
            -
                   | 
| 118 | 
            -
                   | 
| 122 | 
            +
                  s = NumScaler.new(1..8, -5..5)
         | 
| 123 | 
            +
                  expect { s.from(-1) }.to raise_error ArgumentError
         | 
| 124 | 
            +
                  expect { s.from( 0) }.to raise_error ArgumentError
         | 
| 125 | 
            +
                  expect { s.from( 9) }.to raise_error ArgumentError
         | 
| 126 | 
            +
                  expect { s.to(-6) }.to raise_error ArgumentError
         | 
| 127 | 
            +
                  expect { s.to( 6) }.to raise_error ArgumentError
         | 
| 119 128 | 
             
                end
         | 
| 120 129 |  | 
| 121 130 | 
             
                it 'with Float ranges' do
         | 
| 122 | 
            -
                   | 
| 123 | 
            -
                   | 
| 124 | 
            -
                   | 
| 125 | 
            -
                   | 
| 126 | 
            -
                   | 
| 127 | 
            -
                   | 
| 128 | 
            -
                   | 
| 131 | 
            +
                  s = NumScaler.new(0.5..1.25, -5.0..5.0)
         | 
| 132 | 
            +
                  expect { s.from(0.42 ) }.to raise_error ArgumentError
         | 
| 133 | 
            +
                  expect { s.from(0.499) }.to raise_error ArgumentError
         | 
| 134 | 
            +
                  expect { s.from(1.26 ) }.to raise_error ArgumentError
         | 
| 135 | 
            +
                  expect { s.from(1.3  ) }.to raise_error ArgumentError
         | 
| 136 | 
            +
                  expect { s.to(-5.1) }.to raise_error ArgumentError
         | 
| 137 | 
            +
                  expect { s.to( 5.1) }.to raise_error ArgumentError
         | 
| 129 138 | 
             
                end
         | 
| 130 139 | 
             
              end
         | 
| 131 140 |  | 
| 132 141 | 
             
              context 'should :clamp clamp properly' do
         | 
| 133 142 | 
             
                it 'with Integer ranges' do
         | 
| 134 | 
            -
                   | 
| 135 | 
            -
                   | 
| 136 | 
            -
                   | 
| 137 | 
            -
                   | 
| 138 | 
            -
                   | 
| 139 | 
            -
                   | 
| 140 | 
            -
                   | 
| 143 | 
            +
                  s = NumScaler.new(1..8, -32..32, :mode => :clamp)
         | 
| 144 | 
            +
                  expect(s.from(-1)).to eql -32
         | 
| 145 | 
            +
                  expect(s.from( 0)).to eql -32
         | 
| 146 | 
            +
                  expect(s.from( 9)).to eql  32
         | 
| 147 | 
            +
                  expect(s.to(-33)).to eql 1
         | 
| 148 | 
            +
                  expect(s.to(  0)).to eql 5
         | 
| 149 | 
            +
                  expect(s.to( 33)).to eql 8
         | 
| 141 150 | 
             
                end
         | 
| 142 151 |  | 
| 143 152 | 
             
                it 'with Float ranges' do
         | 
| 144 | 
            -
                   | 
| 145 | 
            -
                   | 
| 146 | 
            -
                   | 
| 147 | 
            -
                   | 
| 148 | 
            -
                   | 
| 153 | 
            +
                  s = NumScaler.new(1.0..8.0, -32.0..32.0, :mode => :clamp)
         | 
| 154 | 
            +
                  expect(s.from(0.89)).to eql -32.0
         | 
| 155 | 
            +
                  expect(s.from(8.01)).to eql  32.0
         | 
| 156 | 
            +
                  expect(s.to(-32.1)).to eql 1.0
         | 
| 157 | 
            +
                  expect(s.to( 32.1)).to eql 8.0
         | 
| 149 158 | 
             
                end
         | 
| 150 159 | 
             
              end
         | 
| 151 160 |  | 
| 152 161 | 
             
              context 'should :cycle clamp properly' do
         | 
| 153 162 | 
             
                it 'with Integer ranges' do
         | 
| 154 | 
            -
                   | 
| 155 | 
            -
                   | 
| 156 | 
            -
                   | 
| 157 | 
            -
                   | 
| 158 | 
            -
                   | 
| 159 | 
            -
                   | 
| 160 | 
            -
                   | 
| 161 | 
            -
             | 
| 162 | 
            -
                   | 
| 163 | 
            -
                   | 
| 164 | 
            -
                   | 
| 165 | 
            -
                   | 
| 166 | 
            -
                   | 
| 167 | 
            -
                   | 
| 168 | 
            -
                   | 
| 169 | 
            -
                   | 
| 170 | 
            -
                   | 
| 171 | 
            -
                   | 
| 163 | 
            +
                  s = NumScaler.new(1..8, -8..-1, :mode => :cycle)
         | 
| 164 | 
            +
                  expect(s.from(-2)).to eql -4
         | 
| 165 | 
            +
                  expect(s.from( 0)).to eql -2
         | 
| 166 | 
            +
                  expect(s.from( 2)).to eql -7
         | 
| 167 | 
            +
                  expect(s.from( 9)).to eql -7
         | 
| 168 | 
            +
                  expect(s.to(-9)).to eql 7
         | 
| 169 | 
            +
                  expect(s.to( 0)).to eql 2
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                  s = NumScaler.new(-5..5, 20..30, :mode => :cycle)
         | 
| 172 | 
            +
                  expect(s.from(-8)).to eql 27
         | 
| 173 | 
            +
                  expect(s.from(-7)).to eql 28
         | 
| 174 | 
            +
                  expect(s.from(-6)).to eql 29
         | 
| 175 | 
            +
                  expect(s.from( 6)).to eql 21
         | 
| 176 | 
            +
                  expect(s.from( 7)).to eql 22
         | 
| 177 | 
            +
                  expect(s.to(18)).to eql  3
         | 
| 178 | 
            +
                  expect(s.to(19)).to eql  4
         | 
| 179 | 
            +
                  expect(s.to(31)).to eql -4
         | 
| 180 | 
            +
                  expect(s.to(41)).to eql -4
         | 
| 172 181 | 
             
                end
         | 
| 173 182 |  | 
| 174 183 | 
             
                it 'with Float ranges' do
         | 
| 175 | 
            -
                   | 
| 176 | 
            -
                   | 
| 177 | 
            -
                   | 
| 178 | 
            -
                   | 
| 179 | 
            -
                   | 
| 180 | 
            -
                   | 
| 184 | 
            +
                  s = NumScaler.new(-2.5..2.5, 20.0..30.0, :mode => :cycle)
         | 
| 185 | 
            +
                  expect(s.from(-6.0)).to eql 23.0
         | 
| 186 | 
            +
                  expect(s.from(-2.0)).to eql 21.0
         | 
| 187 | 
            +
                  expect(s.from( 0.0)).to eql 25.0
         | 
| 188 | 
            +
                  expect(s.from( 3.0)).to eql 21.0
         | 
| 189 | 
            +
                  expect(s.from( 6.0)).to eql 27.0
         | 
| 181 190 | 
             
                end
         | 
| 182 191 | 
             
              end
         | 
| 183 192 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: numscaler
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Piotr S. Staszewski
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-05- | 
| 11 | 
            +
            date: 2014-05-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec
         | 
| @@ -60,11 +60,13 @@ extra_rdoc_files: [] | |
| 60 60 | 
             
            files:
         | 
| 61 61 | 
             
            - ".document"
         | 
| 62 62 | 
             
            - ".gitignore"
         | 
| 63 | 
            -
            - ".rspec"
         | 
| 64 63 | 
             
            - ".yardopts"
         | 
| 65 64 | 
             
            - LICENSE.txt
         | 
| 66 65 | 
             
            - README.md
         | 
| 67 66 | 
             
            - Rakefile
         | 
| 67 | 
            +
            - examples/esoteric.rb
         | 
| 68 | 
            +
            - examples/graphing.rb
         | 
| 69 | 
            +
            - examples/units.rb
         | 
| 68 70 | 
             
            - lib/numscaler.rb
         | 
| 69 71 | 
             
            - numscaler.gemspec
         | 
| 70 72 | 
             
            - spec/numscaler_spec.rb
         | 
| @@ -80,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 80 82 | 
             
              requirements:
         | 
| 81 83 | 
             
              - - ">="
         | 
| 82 84 | 
             
                - !ruby/object:Gem::Version
         | 
| 83 | 
            -
                  version:  | 
| 85 | 
            +
                  version: 1.8.7
         | 
| 84 86 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 85 87 | 
             
              requirements:
         | 
| 86 88 | 
             
              - - ">="
         | 
    
        data/.rspec
    DELETED