Sha256: 144997b8e9e8b60aad45e9b4871ad58ab526aac2d59ede1d6e072c162472c9dd

Contents?: true

Size: 770 Bytes

Versions: 2

Compression:

Stored size: 770 Bytes

Contents

class ListProjects < Struct.new :format, :criteria
  def call formatter_class = formatter_class, projects = projects
    formatter(formatter_class).present projects
  end

  def projects catalog = ProjectCatalog.load, criteria = criteria
    catalog.projects criteria
  end

  def formatter(formatter_class, format = format.present? ? eval(format) : default_format)
    formatter_class.new format
  end

  def default_format projects = projects
    {'Name' => 'name'}.merge list_properties_format properties
  end

  private

  def list_properties_format properties
    Hash[properties.map { |p| [p, "property('#{p}').try :last_value"] }]
  end

  def properties
    metrics.collect(&:name).flatten
  end

  def metrics
    projects.collect(&:metrics).flatten
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
techcor-0.0.10 lib/commands/list_projects.rb
techcor-0.0.9 lib/commands/list_projects.rb