Method: PWS::Format.normalize_format

Defined in:
lib/pws/format.rb

.normalize_format(raw_format) ⇒ Object

Converts various version formats into an array of two integers Symbols won’t be changed



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pws/format.rb', line 77

def normalize_format(raw_format)
  case raw_format 
  when Symbol
    return raw_format
  when Array
    format = raw_format[0,2]
  when String, Float, Integer
    format = raw_format.to_s.split('.')[0,2]
  when nil
    return nil
  end
  
  if !format || !format.is_a?(Array) || !format[0]
    raise ArgumentError, 'Invalid format given'
  else
    format.map!(&:to_i)
    format[1] ||= 0
  end
  
  format
end