useragent 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/user_agent/version.rb +89 -0
- metadata +5 -4
@@ -0,0 +1,89 @@
|
|
1
|
+
class UserAgent
|
2
|
+
class Version
|
3
|
+
include ::Comparable
|
4
|
+
|
5
|
+
def self.new(obj)
|
6
|
+
case obj
|
7
|
+
when Version
|
8
|
+
obj
|
9
|
+
when String
|
10
|
+
super
|
11
|
+
else
|
12
|
+
raise ArgumentError, "invalid value for Version: #{obj.inspect}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(str)
|
17
|
+
@str = str
|
18
|
+
|
19
|
+
if str =~ /^\d+$/ || str =~ /^\d+\./
|
20
|
+
@sequences = str.scan(/\d+|[A-Za-z][0-9A-Za-z-]*$/).map { |s| s =~ /^\d+$/ ? s.to_i : s }
|
21
|
+
@comparable = true
|
22
|
+
else
|
23
|
+
@sequences = [str]
|
24
|
+
@comparable = false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_a
|
29
|
+
@sequences.dup
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_str
|
33
|
+
@str.dup
|
34
|
+
end
|
35
|
+
|
36
|
+
def eql?(other)
|
37
|
+
other.is_a?(self.class) && to_s == other.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def ==(other)
|
41
|
+
case other
|
42
|
+
when Version
|
43
|
+
eql?(other)
|
44
|
+
when String
|
45
|
+
eql?(self.class.new(other))
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def <=>(other)
|
52
|
+
case other
|
53
|
+
when Version
|
54
|
+
if @comparable
|
55
|
+
to_a.zip(other.to_a).each do |a, b|
|
56
|
+
if b.nil?
|
57
|
+
return -1
|
58
|
+
elsif a.nil?
|
59
|
+
return 1
|
60
|
+
elsif a.is_a?(String) && b.is_a?(Integer)
|
61
|
+
return -1
|
62
|
+
elsif a.is_a?(Integer) && b.is_a?(String)
|
63
|
+
return 1
|
64
|
+
elsif a == b
|
65
|
+
next
|
66
|
+
else
|
67
|
+
return a <=> b
|
68
|
+
end
|
69
|
+
end
|
70
|
+
0
|
71
|
+
else
|
72
|
+
to_s == other.to_s ? 0 : nil
|
73
|
+
end
|
74
|
+
when String
|
75
|
+
self <=> self.class.new(other)
|
76
|
+
else
|
77
|
+
raise ArgumentError, "comparison of Version with #{other.inspect} failed"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_s
|
82
|
+
to_str
|
83
|
+
end
|
84
|
+
|
85
|
+
def inspect
|
86
|
+
"#<#{self.class} #{to_s}>"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: useragent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Peek
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/user_agent/browsers/webkit.rb
|
38
38
|
- lib/user_agent/comparable.rb
|
39
39
|
- lib/user_agent/operating_systems.rb
|
40
|
+
- lib/user_agent/version.rb
|
40
41
|
- lib/useragent.rb
|
41
42
|
- LICENSE
|
42
43
|
- README.rdoc
|
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
71
|
requirements: []
|
71
72
|
|
72
73
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.4.1
|
74
75
|
signing_key:
|
75
76
|
specification_version: 3
|
76
77
|
summary: HTTP User Agent parser
|