Class: Ukiryu::Models::VersionInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/models/version_info.rb

Overview

Version information with detection method tracking

Represents a version value with metadata about how it was detected. Supports multiple detection methods (command, man_page, etc.) as a fallback hierarchy, NOT mutually exclusive types.

Examples:

Command-based version

VersionInfo.new(
  value: '3.11',
  method_used: :command,
  available_methods: [:command]
)

Man page fallback version

VersionInfo.new(
  value: '2020-09-21',
  method_used: :man_page,
  available_methods: [:command, :man_page]
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, method_used:, available_methods: []) ⇒ VersionInfo

Initialize version info

Parameters:

  • value (String)

    the version value (e.g., “3.11” or “2020-09-21”)

  • method_used (Symbol)

    the method that succeeded (:command, :man_page, etc.)

  • available_methods (Array<Symbol>) (defaults to: [])

    all methods that were available



32
33
34
35
36
# File 'lib/ukiryu/models/version_info.rb', line 32

def initialize(value:, method_used:, available_methods: [])
  @value = value
  @method_used = method_used
  @available_methods = available_methods
end

Instance Attribute Details

#available_methodsObject (readonly)

Returns the value of attribute available_methods.



25
26
27
# File 'lib/ukiryu/models/version_info.rb', line 25

def available_methods
  @available_methods
end

#method_usedObject (readonly)

Returns the value of attribute method_used.



25
26
27
# File 'lib/ukiryu/models/version_info.rb', line 25

def method_used
  @method_used
end

#valueObject (readonly)

Returns the value of attribute value.



25
26
27
# File 'lib/ukiryu/models/version_info.rb', line 25

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean

Equality comparison

Parameters:

  • other (Object)

    the object to compare

Returns:

  • (Boolean)

    true if equal



91
92
93
94
95
96
97
# File 'lib/ukiryu/models/version_info.rb', line 91

def ==(other)
  return false unless other.is_a?(VersionInfo)

  value == other.value &&
    method_used == other.method_used &&
    available_methods == other.available_methods
end

#from_command?Boolean

Check if version was detected via command

Returns:

  • (Boolean)

    true if from command execution



41
42
43
# File 'lib/ukiryu/models/version_info.rb', line 41

def from_command?
  method_used == :command
end

#from_man_page?Boolean

Check if version was detected via man page

Returns:

  • (Boolean)

    true if from man page date



48
49
50
# File 'lib/ukiryu/models/version_info.rb', line 48

def from_man_page?
  method_used == :man_page
end

#from_profile?Boolean

Check if version is from profile (hardcoded)

Returns:

  • (Boolean)

    true if from profile



55
56
57
# File 'lib/ukiryu/models/version_info.rb', line 55

def from_profile?
  method_used == :profile
end

#inspectString

Inspect representation

Returns:

  • (String)

    inspect string



102
103
104
# File 'lib/ukiryu/models/version_info.rb', line 102

def inspect
  "#<VersionInfo value=\"#{value}\" method=#{method_used}>"
end

#to_hHash

Hash representation

Returns:

  • (Hash)

    hash with value, method, and available_methods



79
80
81
82
83
84
85
# File 'lib/ukiryu/models/version_info.rb', line 79

def to_h
  {
    value: value,
    method: method_used,
    available_methods: available_methods
  }
end

#to_sString

Display format with context Adds “(man page)” or “(profile)” suffix only for display, not stored in data

Returns:

  • (String)

    formatted version string



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ukiryu/models/version_info.rb', line 63

def to_s
  case method_used
  when :command
    value
  when :man_page
    "#{value} (man page)"
  when :profile
    value
  else
    value
  end
end