Class: I18nFlow::CLI::LintCommand::AsciiRenderer

Inherits:
Object
  • Object
show all
Includes:
Color
Defined in:
lib/i18n_flow/cli/lint_command/ascii_renderer.rb

Constant Summary collapse

FILE =
__dir__ + '/ascii.erb'

Constants included from Color

Color::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Color

#color

Constructor Details

#initialize(errors, color: true) ⇒ AsciiRenderer

Returns a new instance of AsciiRenderer.



13
14
15
16
# File 'lib/i18n_flow/cli/lint_command/ascii_renderer.rb', line 13

def initialize(errors, color: true)
  @errors = errors
  @color_enabled = !!color
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



11
12
13
# File 'lib/i18n_flow/cli/lint_command/ascii_renderer.rb', line 11

def errors
  @errors
end

Instance Method Details

#color_enabled?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/i18n_flow/cli/lint_command/ascii_renderer.rb', line 22

def color_enabled?
  @color_enabled
end

#error_countObject



30
31
32
# File 'lib/i18n_flow/cli/lint_command/ascii_renderer.rb', line 30

def error_count
  @error_count ||= errors.sum { |_, errs| errs.size }
end

#file_countObject



26
27
28
# File 'lib/i18n_flow/cli/lint_command/ascii_renderer.rb', line 26

def file_count
  @file_count ||= errors.size
end

#renderObject



18
19
20
# File 'lib/i18n_flow/cli/lint_command/ascii_renderer.rb', line 18

def render
  with_color(erb.result(binding))
end

#summary_lineObject



34
35
36
37
38
39
40
41
# File 'lib/i18n_flow/cli/lint_command/ascii_renderer.rb', line 34

def summary_line
  @summary_line ||= 'Found %d %s in %d %s' % [
    error_count,
    error_count == 1 ? 'violation' : 'violations',
    file_count,
    file_count == 1 ? 'file' : 'files',
  ]
end