Class: Version::Token Private

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
Library/Homebrew/version.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A part of a Version.

Direct Known Subclasses

NumericToken, StringToken

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Token

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Token.


45
46
47
# File 'Library/Homebrew/version.rb', line 45

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


43
44
45
# File 'Library/Homebrew/version.rb', line 43

def value
  @value
end

Class Method Details

.create(val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (TypeError)

19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'Library/Homebrew/version.rb', line 19

def self.create(val)
  raise TypeError, "Token value must be a string; got a #{val.class} (#{val})" unless val.respond_to?(:to_str)

  case val
  when /\A#{AlphaToken::PATTERN}\z/o   then AlphaToken
  when /\A#{BetaToken::PATTERN}\z/o    then BetaToken
  when /\A#{RCToken::PATTERN}\z/o      then RCToken
  when /\A#{PreToken::PATTERN}\z/o     then PreToken
  when /\A#{PatchToken::PATTERN}\z/o   then PatchToken
  when /\A#{NumericToken::PATTERN}\z/o then NumericToken
  when /\A#{StringToken::PATTERN}\z/o  then StringToken
  end.new(val)
end

.from(val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


33
34
35
36
37
38
39
40
41
# File 'Library/Homebrew/version.rb', line 33

def self.from(val)
  case val
  when Token   then val
  when String  then Token.create(val)
  when Integer then Token.create(val.to_s)
  when nil     then NULL_TOKEN
  else NULL_TOKEN if val.respond_to?(:null?) && val.null?
  end
end

Instance Method Details

#hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


53
54
55
# File 'Library/Homebrew/version.rb', line 53

def hash
  value.hash
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


49
50
51
# File 'Library/Homebrew/version.rb', line 49

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

#numeric?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

69
70
71
# File 'Library/Homebrew/version.rb', line 69

def numeric?
  false
end

#to_fObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


57
58
59
# File 'Library/Homebrew/version.rb', line 57

def to_f
  value.to_f
end

#to_iObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


61
62
63
# File 'Library/Homebrew/version.rb', line 61

def to_i
  value.to_i
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


65
66
67
# File 'Library/Homebrew/version.rb', line 65

def to_s
  value.to_s
end