ruby-mext 0.19.0 → 0.20.0
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/lib/mext/array.rb +1 -0
- data/lib/mext/array/compressed_array.rb +73 -0
- data/lib/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 63132a163bb993330fdd3269ba1cc18aaf83cde43985267cced72504b2fdfe2a
         | 
| 4 | 
            +
              data.tar.gz: dbf545a3c39f962c05b032c6656b75211ba7bbb943f96cb3991752111c2dc268
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4b360ca1cd4528a6d6eedde087f9c4beb9deea6baaf699338edc81ca50f71fbba0e5f9d19234ef5ec47c0d18b160649b1e4882d2c3a74e6268978c6db839f7b9
         | 
| 7 | 
            +
              data.tar.gz: 4125cd097c4cc0474230a8fb89e1e35616e5dfb013acb1c4fddc9d16583d4cef5bdd478028abb93fe04795fc0ca8b3409feb2b4e3fe3c2130087b4b99a9bcc3c
         | 
    
        data/lib/mext/array.rb
    CHANGED
    
    
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            module Mext
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              #
         | 
| 4 | 
            +
              # +Mext::CompressedArray+
         | 
| 5 | 
            +
              #
         | 
| 6 | 
            +
              # is an +array+ in which values are expanded according to the following
         | 
| 7 | 
            +
              # format: if a value is a 2-place array it is interpreted as:
         | 
| 8 | 
            +
              # +[value, num_of_repetitions]+. The array is actually expanded during
         | 
| 9 | 
            +
              # creation so there is currently no way to retrieve the original format.
         | 
| 10 | 
            +
              #
         | 
| 11 | 
            +
              class CompressedArray < Array
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                #
         | 
| 14 | 
            +
                # +Mext::CompressedArray.new(me = [])+
         | 
| 15 | 
            +
                #
         | 
| 16 | 
            +
                # create a array with a special array whose format accept the following
         | 
| 17 | 
            +
                # values:
         | 
| 18 | 
            +
                # * single values (go untreated)
         | 
| 19 | 
            +
                # * arrays of two values (interpreted as +[value, num_of_repetitions]+ -
         | 
| 20 | 
            +
                #   +num_of_repetitions+ value is checked to be a +Fixnum+ to expand
         | 
| 21 | 
            +
                #   +value+ for +num_of_repetitions+ (otherwise the array is passed unprocessed)
         | 
| 22 | 
            +
                # * anything else is passed unprocessed
         | 
| 23 | 
            +
                #
         | 
| 24 | 
            +
                def initialize(me = [])
         | 
| 25 | 
            +
                  new_array = expand(me)
         | 
| 26 | 
            +
                  self.replace(new_array)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                class << self
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  #
         | 
| 32 | 
            +
                  # +from_yaml(hash)+
         | 
| 33 | 
            +
                  #
         | 
| 34 | 
            +
                  # create from a +yaml+ +Hash+ configuration
         | 
| 35 | 
            +
                  #
         | 
| 36 | 
            +
                  def from_yaml(ha)
         | 
| 37 | 
            +
                    raise ArgumentError unless ha.kind_of?(Hash) && ha.has_key?('args')
         | 
| 38 | 
            +
                    args = ha['args']
         | 
| 39 | 
            +
                    new(args)
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              private
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def expand(a)
         | 
| 47 | 
            +
                  res = []
         | 
| 48 | 
            +
                  a.each do
         | 
| 49 | 
            +
                    |val|
         | 
| 50 | 
            +
                    if expand_value?(val)
         | 
| 51 | 
            +
                      ex_val = expand_value(val)
         | 
| 52 | 
            +
                      res.concat(ex_val)
         | 
| 53 | 
            +
                    else
         | 
| 54 | 
            +
                      res << val
         | 
| 55 | 
            +
                    end
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
                  res
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def expand_value?(val)
         | 
| 61 | 
            +
                  val.kind_of?(Array) && (val.size == 2) && val[1].is_a?(Fixnum)
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                def expand_value(val)
         | 
| 65 | 
            +
                  res = []
         | 
| 66 | 
            +
                  value = val[0]
         | 
| 67 | 
            +
                  0.upto(val[1]-1) { |n| res << value }
         | 
| 68 | 
            +
                  res
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            end
         | 
    
        data/lib/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ruby-mext
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.20.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Nicola Bernardini
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020- | 
| 11 | 
            +
            date: 2020-05-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: wavefile
         | 
| @@ -144,6 +144,7 @@ files: | |
| 144 144 | 
             
            - lib/mext.rb
         | 
| 145 145 | 
             
            - lib/mext/array.rb
         | 
| 146 146 | 
             
            - lib/mext/array/choose.rb
         | 
| 147 | 
            +
            - lib/mext/array/compressed_array.rb
         | 
| 147 148 | 
             
            - lib/mext/array/dotop.rb
         | 
| 148 149 | 
             
            - lib/mext/array/endless_array.rb
         | 
| 149 150 | 
             
            - lib/mext/array/fill.rb
         |