class Text::Checkm::Manifest

Attributes

entries[R]
fields[R]
path[R]
version[R]

Public Class Methods

new(checkm, args = {}) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/text/checkm/manifest.rb, line 13
def initialize(checkm, args = {})
  @args = args
  @version = nil
  @checkm = checkm
  @lines = checkm.split "\n"
  @entries = []
  @eof = false
  @fields = nil
  @path = args[:path] # TODO: something less hacky
  @path ||= Dir.pwd

  parse_lines
  # xxx error on empty entries?
  @lines.unshift('#%checkm_0.7') and (@version = '0.7') if @version.nil?
end
parse(str, args = {}) click to toggle source
# File lib/text/checkm/manifest.rb, line 6
def self.parse(str, args = {})
  Manifest.new str, args
end

Public Instance Methods

add(path, args = {}) click to toggle source
# File lib/text/checkm/manifest.rb, line 37
def add(path, args = {})
  line = Entry.create path, args

  Manifest.new [@lines, line].flatten.join("\n"), @args
end
remove(path) click to toggle source
# File lib/text/checkm/manifest.rb, line 43
def remove(path)
  Manifest.new @lines.reject { |x| x =~ /^@?#{path}/ }.join("\n"), @args
end
to_h() click to toggle source
# File lib/text/checkm/manifest.rb, line 51
def to_h
  {}.tap do |h|
    entries.each do |e|
      source = e.sourcefileorurl
      (h[source] ||= []) << e
    end
  end
end
to_s() click to toggle source
# File lib/text/checkm/manifest.rb, line 47
def to_s
  @lines.join("\n")
end
valid?() click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/text/checkm/manifest.rb, line 31
def valid?
  return true if @entries.empty?

  @entries.map(&:valid?).none? { |b| b == false }
end

Private Instance Methods

parse_comment(_line) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/text/checkm/manifest.rb, line 99
def parse_comment(_line)
  # do nothing
end
parse_header(line) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/text/checkm/manifest.rb, line 82
def parse_header(line)
  case line
  when /^#%checkm/
    match = /^#%checkm_(\d+)\.(\d+)/.match line
    @version = "#{match[1]}.#{match[2]}" if match
  when /^#%eof/
    @eof = true
  when /^#%fields/
    list = line.split('|')
    list.shift
    @fields = list.map { |v| v.strip.downcase }
  when /^#%prefix/, /^#%profile/
    # do nothing
  end
end
parse_line(line) click to toggle source
# File lib/text/checkm/manifest.rb, line 103
def parse_line(line)
  @entries << Entry.new(line, self)
end
parse_lines() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/text/checkm/manifest.rb, line 63
def parse_lines
  @lines.each do |line|
    case line
    when /^$/
      # do nothing
    when /^#%/
      parse_header line
    when /^#/
      parse_comment line
    # when /^@/
    #   parse_line line
    else
      parse_line line
    end
  end
end