Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/boris/helpers/array.rb
Instance Method Summary (collapse)
- - (Object) strip_string_values_in_array
- - (Object) to_ms_product_key
- - (Object) to_nil_hash
- - (Object) to_wwn
Instance Method Details
- (Object) strip_string_values_in_array
2 3 4 5 6 7 8 |
# File 'lib/boris/helpers/array.rb', line 2 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 |
- (Object) to_ms_product_key
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/boris/helpers/array.rb', line 10 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 |
- (Object) to_nil_hash
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/boris/helpers/array.rb', line 40 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 |
- (Object) to_wwn
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/boris/helpers/array.rb', line 52 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 |