Class: GithubStats::CLI::SpaceSeperatedLinePerResultResultsView

Inherits:
Object
  • Object
show all
Defined in:
lib/github_stats/cli.rb

Overview

Transforms a result set into a space-seperated table the results hash keys becoming the table headers and line breaks between rows.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ SpaceSeperatedLinePerResultResultsView

Returns a new instance of SpaceSeperatedLinePerResultResultsView.



49
50
51
# File 'lib/github_stats/cli.rb', line 49

def initialize(results)
  self.results = results
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



48
49
50
# File 'lib/github_stats/cli.rb', line 48

def results
  @results
end

Instance Method Details

#fieldsObject



53
54
55
# File 'lib/github_stats/cli.rb', line 53

def fields
  results.keys
end

#to_sObject



57
58
59
60
61
# File 'lib/github_stats/cli.rb', line 57

def to_s
  fields.join(' ') + "\n" + results.map do |result|
    fields.map(&result.method(:fetch)).join(' ')
  end.join("\n")
end