Class: BundleOutdatedFormatter::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle_outdated_formatter/formatter.rb

Overview

Formatter for all formats

Constant Summary collapse

GEM_REGEXP =
/\A\* (?<gem>.+) \(/.freeze
NEWEST_REGEXP =
/newest (?<newest>[\d.]+)/.freeze
INSTALLED_REGEXP =
/installed (?<installed>[\d.]+)/.freeze
REQUESTED_REGEXP =
/requested (?<requested>.+)\)/.freeze
GROUPS_REGEXP =
/in groups? "(?<groups>.+)"/.freeze
TABLE_FORMAT_REGEXP =
/Gem +Current +Latest +Requested +Groups/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Formatter

Returns a new instance of Formatter.



13
14
15
16
17
18
# File 'lib/bundle_outdated_formatter/formatter.rb', line 13

def initialize(options)
  @pretty = options[:pretty]
  @style = options[:style]
  @columns = options[:column]
  @outdated_gems = []
end

Instance Method Details

#read_stdinObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bundle_outdated_formatter/formatter.rb', line 20

def read_stdin
  @outdated_gems = STDIN.each.to_a.map(&:strip).reject(&:empty?)

  if (header_index = find_table_header_index(@outdated_gems))
    header = @outdated_gems[header_index]
    pos = table_pos(header)
    @outdated_gems.map!.with_index do |line, index|
      find_gem_for_table_format(line, pos) if header_index < index
    end
  else
    @outdated_gems.map! do |line|
      find_gem(line)
    end
  end
  @outdated_gems.compact!
end