Module: Ukiryu::ManPageParser

Defined in:
lib/ukiryu/man_page_parser.rb

Overview

Man page date parser for extracting version information

Parses man page ‘.Dd` macros to extract dates as version information. Used as fallback for system tools that don’t support –version flags.

Examples:

Parse man page date

date = ManPageParser.parse_date('/usr/share/man/man1/xargs.1')
# => "2020-09-21"

Class Method Summary collapse

Class Method Details

.parse_date(man_page_path) ⇒ String?

Parse date from man page

Extracts the ‘.Dd` (date) macro from a man page and converts it to ISO 8601 format (YYYY-MM-DD).

Parameters:

  • man_page_path (String)

    path to the man page file

Returns:

  • (String, nil)

    ISO 8601 date string or nil if not found



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ukiryu/man_page_parser.rb', line 24

def parse_date(man_page_path)
  return nil unless man_page_path
  return nil unless File.exist?(man_page_path)

  content = File.read(man_page_path, encoding: 'UTF-8')

  # Find .Dd line
  # Format: .Dd Month DD, YYYY or .Dd DD Month YYYY
  dd_line = content.lines.find { |line| line =~ /^\.Dd\s+/ }

  return nil unless dd_line

  # Extract and parse date
  extract_date_from_dd_line(dd_line)
rescue Errno::ENOENT, Errno::EACCES
  # File not found or inaccessible - silent failure
  nil
end

.parse_from_fallback(possible_paths) ⇒ String?

Parse date from multiple possible man page locations

Tries multiple paths in order and returns the first successfully parsed date.

Parameters:

  • possible_paths (Array<String>)

    list of possible man page paths

Returns:

  • (String, nil)

    ISO 8601 date string or nil if none found



67
68
69
70
71
72
73
74
# File 'lib/ukiryu/man_page_parser.rb', line 67

def parse_from_fallback(possible_paths)
  possible_paths.each do |path|
    date = parse_date(path)
    return date if date
  end

  nil
end

.resolve_man_page_path(tool_name, paths = {}) ⇒ String?

Get man page path for a tool on current platform

Parameters:

  • tool_name (String)

    the tool name

  • paths (Hash) (defaults to: {})

    platform-specific path templates

Returns:

  • (String, nil)

    resolved man page path or nil



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ukiryu/man_page_parser.rb', line 48

def resolve_man_page_path(tool_name, paths = {})
  platform = Ukiryu::Platform.current

  # Get platform-specific path pattern
  path_pattern = paths[platform]

  return nil unless path_pattern

  # Expand tool name placeholder if present
  path_pattern.gsub('{tool}', tool_name)
end