Class: GithubStats::CLI::CommaSeperatedLinePerResultResultsView

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) ⇒ CommaSeperatedLinePerResultResultsView

Returns a new instance of CommaSeperatedLinePerResultResultsView.



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

def initialize(results)
  self.results = results
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



51
52
53
# File 'lib/github_stats/cli.rb', line 51

def results
  @results
end

Instance Method Details

#fieldsObject



56
57
58
# File 'lib/github_stats/cli.rb', line 56

def fields
  results.keys
end

#to_sObject



60
61
62
63
64
# File 'lib/github_stats/cli.rb', line 60

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