core_extended 0.0.6 → 0.0.7
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.
- data/lib/core_extended/hash.rb +13 -0
- data/lib/core_extended/version.rb +1 -1
- data/spec/hash_spec.rb +33 -0
- metadata +2 -8
    
        data/lib/core_extended/hash.rb
    CHANGED
    
    | @@ -2,6 +2,19 @@ class Hash | |
| 2 2 |  | 
| 3 3 | 
             
              Inflector = Struct.new :method, :arguments
         | 
| 4 4 |  | 
| 5 | 
            +
              def dictionary(parent_key=nil)
         | 
| 6 | 
            +
                Hash.new.tap do |hash|
         | 
| 7 | 
            +
                  each do |k,v|
         | 
| 8 | 
            +
                    key = [parent_key, k].compact.join('.')
         | 
| 9 | 
            +
                    if v.is_a? Hash
         | 
| 10 | 
            +
                      hash.merge! v.dictionary(key)
         | 
| 11 | 
            +
                    else
         | 
| 12 | 
            +
                      hash[key] = v
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 5 18 | 
             
              def self.inflectors
         | 
| 6 19 | 
             
                @inflectors ||= []
         | 
| 7 20 | 
             
              end
         | 
    
        data/spec/hash_spec.rb
    CHANGED
    
    | @@ -113,4 +113,37 @@ describe Hash do | |
| 113 113 |  | 
| 114 114 | 
             
              end
         | 
| 115 115 |  | 
| 116 | 
            +
              describe 'Dictionary' do
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                it 'Simple hash' do
         | 
| 119 | 
            +
                  hash = {key_1: 1, 'key_2' => 'text', key_3: []}
         | 
| 120 | 
            +
                  hash.dictionary.must_equal 'key_1' => 1, 
         | 
| 121 | 
            +
                                             'key_2' => 'text', 
         | 
| 122 | 
            +
                                             'key_3' => []
         | 
| 123 | 
            +
                end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                it 'Nested hashes' do
         | 
| 126 | 
            +
                  hash = {
         | 
| 127 | 
            +
                    key_1: 1,
         | 
| 128 | 
            +
                    'key_2' => 'text',
         | 
| 129 | 
            +
                    key_3: [],
         | 
| 130 | 
            +
                    key_4: {
         | 
| 131 | 
            +
                      1 => '4.1',
         | 
| 132 | 
            +
                      2 => {
         | 
| 133 | 
            +
                        1 => '4.2.1',
         | 
| 134 | 
            +
                        2 => '4.2.2'
         | 
| 135 | 
            +
                      }
         | 
| 136 | 
            +
                    }
         | 
| 137 | 
            +
                  }
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                  hash.dictionary.must_equal 'key_1' => 1, 
         | 
| 140 | 
            +
                                             'key_2' => 'text', 
         | 
| 141 | 
            +
                                             'key_3' => [], 
         | 
| 142 | 
            +
                                             'key_4.1' => '4.1', 
         | 
| 143 | 
            +
                                             'key_4.2.1' => '4.2.1', 
         | 
| 144 | 
            +
                                             'key_4.2.2' => '4.2.2'
         | 
| 145 | 
            +
                end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
              end
         | 
| 148 | 
            +
             | 
| 116 149 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: core_extended
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-09- | 
| 12 | 
            +
            date: 2013-09-20 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         | 
| @@ -174,18 +174,12 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 174 174 | 
             
              - - ! '>='
         | 
| 175 175 | 
             
                - !ruby/object:Gem::Version
         | 
| 176 176 | 
             
                  version: '0'
         | 
| 177 | 
            -
                  segments:
         | 
| 178 | 
            -
                  - 0
         | 
| 179 | 
            -
                  hash: 2176153387559094585
         | 
| 180 177 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 181 178 | 
             
              none: false
         | 
| 182 179 | 
             
              requirements:
         | 
| 183 180 | 
             
              - - ! '>='
         | 
| 184 181 | 
             
                - !ruby/object:Gem::Version
         | 
| 185 182 | 
             
                  version: '0'
         | 
| 186 | 
            -
                  segments:
         | 
| 187 | 
            -
                  - 0
         | 
| 188 | 
            -
                  hash: 2176153387559094585
         | 
| 189 183 | 
             
            requirements: []
         | 
| 190 184 | 
             
            rubyforge_project: 
         | 
| 191 185 | 
             
            rubygems_version: 1.8.25
         |