Sha256: 3ef3f7d2c74271384fe06f761fa59653e3dddd7869a52ecaef4620e8a9d64fd4

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class Solr::Util
  # paired_array_each([key1,value1,key2,value2]) yields twice:
  #     |key1,value1|  and |key2,value2|
  def self.paired_array_each(a, &block)
    0.upto(a.size / 2 - 1) do |i|
      n = i * 2
      yield(a[n], a[n+1])
    end
  end

  # paired_array_to_hash([key1,value1,key2,value2]) => {key1 => value1, key2, value2}
  def self.paired_array_to_hash(a)
    h = {}
    
    paired_array_each(a) do |key,value|
      h[key] = value
    end
    
    h
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solr-ruby-0.0.3 lib/solr/util.rb
solr-ruby-0.0.2 lib/solr/util.rb