Class: UserAgentParser::Version
- Inherits:
-
Object
- Object
- UserAgentParser::Version
- 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-]*$/
Instance Attribute Summary collapse
-
#version ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(*args) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #major ⇒ Object
- #minor ⇒ Object
- #patch ⇒ Object
- #patch_minor ⇒ Object
-
#segments ⇒ Object
Private.
Constructor Details
#initialize(*args) ⇒ Version
Returns a new instance of Version.
11 12 13 14 15 16 17 18 |
# File 'lib/user_agent_parser/version.rb', line 11 def initialize(*args) if args.length == 1 && args.first.is_a?(String) @version = args.first.to_s.strip else @segments = args.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.
8 9 10 |
# File 'lib/user_agent_parser/version.rb', line 8 def version @version end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
40 41 42 43 |
# File 'lib/user_agent_parser/version.rb', line 40 def eql?(other) self.class.eql?(other.class) && version == other.version end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/user_agent_parser/version.rb', line 36 def inspect "#<#{self.class} #{to_s}>" end |
#major ⇒ Object
20 21 22 |
# File 'lib/user_agent_parser/version.rb', line 20 def major segments[0] end |
#minor ⇒ Object
24 25 26 |
# File 'lib/user_agent_parser/version.rb', line 24 def minor segments[1] end |
#patch ⇒ Object
28 29 30 |
# File 'lib/user_agent_parser/version.rb', line 28 def patch segments[2] end |
#patch_minor ⇒ Object
32 33 34 |
# File 'lib/user_agent_parser/version.rb', line 32 def patch_minor segments[3] end |
#segments ⇒ Object
Private
48 49 50 |
# File 'lib/user_agent_parser/version.rb', line 48 def segments @segments ||= version.scan(SEGMENTS_REGEX) end |