Class: Archimate::Cli::Stats
- Inherits:
-
Object
- Object
- Archimate::Cli::Stats
- Defined in:
- lib/archimate/cli/stats.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#output_io ⇒ Object
readonly
Returns the value of attribute output_io.
Instance Method Summary collapse
- #elements_by_layer ⇒ Object
-
#initialize(model, output_io) ⇒ Stats
constructor
A new instance of Stats.
- #row(title, size, color) ⇒ Object
- #statistics ⇒ Object
- #title_width ⇒ Object
Constructor Details
#initialize(model, output_io) ⇒ Stats
Returns a new instance of Stats.
9 10 11 12 |
# File 'lib/archimate/cli/stats.rb', line 9 def initialize(model, output_io) @model = model @output_io = output_io end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/archimate/cli/stats.rb', line 7 def model @model end |
#output_io ⇒ Object (readonly)
Returns the value of attribute output_io.
6 7 8 |
# File 'lib/archimate/cli/stats.rb', line 6 def output_io @output_io end |
Instance Method Details
#elements_by_layer ⇒ Object
26 27 28 |
# File 'lib/archimate/cli/stats.rb', line 26 def elements_by_layer @elements_by_layer ||= model.elements.group_by(&:layer) end |
#row(title, size, color) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/archimate/cli/stats.rb', line 34 def row(title, size, color) @title_format_str ||= "%#{title_width}s" @count_format_str ||= "%7d" Color.color(format(@title_format_str, title), color) + format(@count_format_str, size) end |
#statistics ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/archimate/cli/stats.rb', line 14 def statistics output_io.puts Color.color("#{model.name} ArchiMate Model Statistics\n", :headline) output_io.puts "Elements:" elements_by_layer.each do |layer, elements| output_io.puts row(layer, elements.size, layer) end output_io.puts row("Total Elements", model.elements.size, :horizontal_line) output_io.puts row("Relationships", model.relationships.size, :Relationship) output_io.puts row("Diagrams", model.diagrams.size, :Diagram) end |
#title_width ⇒ Object
30 31 32 |
# File 'lib/archimate/cli/stats.rb', line 30 def title_width @title_width ||= (elements_by_layer.keys + ["Total Elements"]).map(&:to_s).map(&:size).max end |