class BrewOutdatedFormatter::Formatter

Formatter for all formats

Constants

COLUMNS
CURRENT_REGEXP
FORMULA_REGEXP
INSTALLED_REGEXP
PINNED_REGEXP

Public Class Methods

new(options) click to toggle source
# File lib/brew_outdated_formatter/formatter.rb, line 11
def initialize(options)
  @pretty = options[:pretty]
  @outdated_formulas = []
end

Public Instance Methods

read_stdin() click to toggle source
# File lib/brew_outdated_formatter/formatter.rb, line 16
def read_stdin
  @outdated_formulas = STDIN.each.to_a.map(&:strip).reject(&:empty?)

  @outdated_formulas.map! do |line|
    find_formula(line)
  end

  @outdated_formulas.compact!
end

Private Instance Methods

find_formula(line) click to toggle source
# File lib/brew_outdated_formatter/formatter.rb, line 28
def find_formula(line)
  matched = match_formula(line)
  return unless match_formula?(matched)

  {
    'formula'   => formula_text(matched[:formula], :formula),
    'installed' => formula_text(matched[:installed], :installed),
    'current'   => formula_text(matched[:current], :current),
    'pinned'    => formula_text(matched[:pinned], :pinned)
  }
end
formula_text(text, name) click to toggle source
# File lib/brew_outdated_formatter/formatter.rb, line 55
def formula_text(text, name)
  text ? text[name] : ''
end
match_formula(line) click to toggle source
# File lib/brew_outdated_formatter/formatter.rb, line 40
def match_formula(line)
  {
    formula:   FORMULA_REGEXP.match(line),
    installed: INSTALLED_REGEXP.match(line),
    current:   CURRENT_REGEXP.match(line),
    pinned:    PINNED_REGEXP.match(line)
  }
end
match_formula?(matched) click to toggle source
# File lib/brew_outdated_formatter/formatter.rb, line 49
def match_formula?(matched)
  COLUMNS.any? do |column|
    !matched[column.to_sym].nil?
  end
end
xml_formatter() click to toggle source
# File lib/brew_outdated_formatter/formatter.rb, line 59
def xml_formatter
  return REXML::Formatters::Default.new unless @pretty

  formatter = REXML::Formatters::Pretty.new
  formatter.compact = true
  formatter
end