lib/user_agent/version.rb in useragent-0.10.0 vs lib/user_agent/version.rb in useragent-0.11.0
- old
+ new
@@ -1,32 +1,44 @@
class UserAgent
class Version
include ::Comparable
- def self.new(obj)
+ def self.new(obj = nil)
case obj
when Version
obj
when String
super
+ when NilClass
+ super("")
else
raise ArgumentError, "invalid value for Version: #{obj.inspect}"
end
end
def initialize(str)
@str = str
- if str =~ /^\d+$/ || str =~ /^\d+\./
+ if @str =~ /^\s*$/
+ @nil = true
+ @sequences = []
+ @comparable = false
+ elsif str =~ /^\d+$/ || str =~ /^\d+\./
+ @nil = false
@sequences = str.scan(/\d+|[A-Za-z][0-9A-Za-z-]*$/).map { |s| s =~ /^\d+$/ ? s.to_i : s }
@comparable = true
else
+ @nil = false
@sequences = [str]
@comparable = false
end
end
+ def nil?
+ @nil
+ end
+
def to_a
@sequences.dup
end
def to_str
@@ -41,10 +53,12 @@
case other
when Version
eql?(other)
when String
eql?(self.class.new(other))
+ when NilClass
+ nil?
else
false
end
end
@@ -70,10 +84,10 @@
elsif to_s == other.to_s
return 0
else
return -1
end
- when String
+ when String, NilClass
self <=> self.class.new(other)
else
nil
end
end