Class: UserAgentParser::Version

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#versionObject (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: ==

Returns:

  • (Boolean)


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

#inspectObject



36
37
38
# File 'lib/user_agent_parser/version.rb', line 36

def inspect
  "#<#{self.class} #{to_s}>"
end

#majorObject



20
21
22
# File 'lib/user_agent_parser/version.rb', line 20

def major
  segments[0]
end

#minorObject



24
25
26
# File 'lib/user_agent_parser/version.rb', line 24

def minor
  segments[1]
end

#patchObject



28
29
30
# File 'lib/user_agent_parser/version.rb', line 28

def patch
  segments[2]
end

#patch_minorObject



32
33
34
# File 'lib/user_agent_parser/version.rb', line 32

def patch_minor
  segments[3]
end

#segmentsObject

Private



48
49
50
# File 'lib/user_agent_parser/version.rb', line 48

def segments
  @segments ||= version.scan(SEGMENTS_REGEX)
end