Sha256: 8c32579e551c87f0169e32b3c0f34527141212b045d89995c669b54093840183

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

class Array
  def strip_string_values_in_array
    self.map! do |val|
      val.strip_string_values_in_array if val.is_a?(Array)
      val.strip_string_values_in_hash if val.is_a?(Hash)
      val.is_a?(String) ? val.strip : val
    end
  end
  
  def to_ms_product_key
    valid_chars = 'BCDFGHJKMPQRTVWXY2346789'.scan(/./)

    product_key = nil
    
    raw_product_key = []

    52.upto(66) do |idx|
      raw_product_key << self[idx]
    end

    24.downto(0) do |a|
      b = 0

      14.downto(0) do |c|
        b = b * 256 ^ raw_product_key[c]
        raw_product_key[c] = (b / 24).to_i
        b = b.remainder(24)
      end

      product_key = "#{valid_chars[b]}#{product_key}"

      if a.remainder(5) == 0 && a != 0
        product_key = "-#{product_key}"
      end
    end

    return product_key.upcase
  end

  def to_nil_hash
    h = Hash.new
    self.each do |item|
      if item.kind_of?(Hash)
        h.merge!(item)
      else
        h[item.to_sym] = nil
      end
    end
    return h
  end

  def to_wwn
    wwn = []

    0.upto(7) do |i|
      hex = self[i].to_s(16)
      hex = "0#{hex}" if self[i] < 16
      wwn << hex
    end
    
    return wwn.join
  end
end

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
boris-1.0.0.beta.1 ./lib/boris/helpers/array.rb
boris-1.0.0.beta.1 lib/boris/helpers/array.rb