Class: UserAgentParser::Version
- Inherits:
-
Object
- Object
- UserAgentParser::Version
- Includes:
- Comparable
- Defined in:
- lib/user_agent_parser/version.rb
Constant Summary collapse
- SEGMENTS_REGEX =
Private: Regex used to split string version string into major, minor, patch, and patch_minor.
/\d+\-\d+|\d+[a-zA-Z]+$|\d+|[A-Za-z][0-9A-Za-z-]*$/.freeze
Instance Attribute Summary collapse
-
#version ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(*args) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #major ⇒ Object
- #minor ⇒ Object
- #patch ⇒ Object
- #patch_minor ⇒ Object
- #segments ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(*args) ⇒ Version
Returns a new instance of Version.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/user_agent_parser/version.rb', line 16 def initialize(*args) # If only one string argument is given, assume a complete version string # and attempt to parse it if args.length == 1 && args.first.is_a?(String) @version = args.first.to_s.strip else @segments = args.compact.map(&:to_s).map(&:strip) @version = segments.join('.') end end |
Instance Attribute Details
#version ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute version.
13 14 15 |
# File 'lib/user_agent_parser/version.rb', line 13 def version @version end |
Instance Method Details
#<=>(other) ⇒ Object
52 53 54 |
# File 'lib/user_agent_parser/version.rb', line 52 def <=>(other) Gem::Version.new(version).<=>(Gem::Version.new(other.to_s)) end |
#eql?(other) ⇒ Boolean
47 48 49 50 |
# File 'lib/user_agent_parser/version.rb', line 47 def eql?(other) self.class.eql?(other.class) && version == other.version end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/user_agent_parser/version.rb', line 43 def inspect "#<#{self.class} #{self}>" end |
#major ⇒ Object
27 28 29 |
# File 'lib/user_agent_parser/version.rb', line 27 def major segments[0] end |
#minor ⇒ Object
31 32 33 |
# File 'lib/user_agent_parser/version.rb', line 31 def minor segments[1] end |
#patch ⇒ Object
35 36 37 |
# File 'lib/user_agent_parser/version.rb', line 35 def patch segments[2] end |
#patch_minor ⇒ Object
39 40 41 |
# File 'lib/user_agent_parser/version.rb', line 39 def patch_minor segments[3] end |
#segments ⇒ Object
56 57 58 |
# File 'lib/user_agent_parser/version.rb', line 56 def segments @segments ||= version.scan(SEGMENTS_REGEX) end |
#to_h ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/user_agent_parser/version.rb', line 60 def to_h { version: version, major: major, minor: minor, patch: patch, patch_minor: patch_minor } end |