class Translatomatic::Config::Display

Methods for displaying configuration

Constants

CONFIG_HEADING_MAP
CONFIG_VALUE_MAP

Attributes

options[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/translatomatic/config/display.rb, line 7
def initialize(opts = {})
  @options = opts
  @config_params = opts[:config_params]
  raise t('config.one_at_a_time') if opts[:user] && opts[:project]
end

Public Instance Methods

config_table_body() click to toggle source

@return [Array<Array<String>>] Configuration table

# File lib/translatomatic/config/display.rb, line 14
def config_table_body
  columns = options[:columns] || []
  rows = config_table_rows(columns)
  if rows.present?
    headings = columns.collect { |i| CONFIG_HEADING_MAP[i] }
    rows = add_table_heading(rows, headings)
  end
  rows
end

Private Instance Methods

add_table_heading(rows, headings) click to toggle source
# File lib/translatomatic/config/display.rb, line 49
def add_table_heading(rows, headings)
  underscores = headings.collect { |i| i.gsub(/\w/, '=') }
  [headings, underscores] + rows
end
config_table_column_value(option, column) click to toggle source
# File lib/translatomatic/config/display.rb, line 70
def config_table_column_value(option, column)
  return option_value(option) if column == :value
  value_method = CONFIG_VALUE_MAP[column]
  return option.send(value_method).to_s if value_method
  raise "unhandled column type: #{column}"
end
config_table_rows(columns) click to toggle source
# File lib/translatomatic/config/display.rb, line 54
def config_table_rows(columns)
  opts = Options.options.values.select { |i| display_option?(i) }
  rows = opts.collect { |i| option_to_table_row(i, columns) }
  rows.sort_by { |i| i[0] }
  rows
end
display_option?(option) click to toggle source
# File lib/translatomatic/config/display.rb, line 41
def display_option?(option)
  key = option.name.to_s
  have_conf = Translatomatic.config.include?(key, @options)
  return false if option.command_line_only
  return false if options[:skip_blanks] && !have_conf
  true
end
option_to_table_row(option, columns) click to toggle source
# File lib/translatomatic/config/display.rb, line 61
def option_to_table_row(option, columns)
  columns.collect { |i| config_table_column_value(option, i) }
end
option_value(option) click to toggle source
# File lib/translatomatic/config/display.rb, line 65
def option_value(option)
  value = Translatomatic.config.get(option.name, @options)
  value.nil? ? '-' : value
end