class Elasticsearch::API::Response::Renderers::BaseRenderer
Public Class Methods
new(options = {})
click to toggle source
# File lib/elasticsearch/api/response/renderers/base_renderer.rb, line 10 def initialize(options = {}) disable_colorization if options[:colorize] == false @max = options[:max] || 3 @plain_score = options[:plain_score] == true @show_values = options[:show_values] == true end
Private Instance Methods
field(str)
click to toggle source
# File lib/elasticsearch/api/response/renderers/base_renderer.rb, line 50 def field(str) ansi(str, :blue ,:bright) end
render_description(description)
click to toggle source
# File lib/elasticsearch/api/response/renderers/base_renderer.rb, line 35 def render_description(description) text = '' text = description.operation if description.operation if description.field && description.value if @show_values text += "(#{field(description.field)}:#{value(description.value)})" else text += "(#{field(description.field)})" end elsif description.field text += "(#{field(description.field)})" end text end
render_node(node)
click to toggle source
# File lib/elasticsearch/api/response/renderers/base_renderer.rb, line 28 def render_node(node) text = render_score(node.score) desc = render_description(node.description) text = "#{text}(#{desc})" unless desc.empty? text end
render_score(score)
click to toggle source
# File lib/elasticsearch/api/response/renderers/base_renderer.rb, line 19 def render_score(score) value = if !@plain_score && score > 1_000 sprintf("%1.2g", score.round(2)) else score.round(2).to_s end ansi(value, :magenta, :bright) end
value(str)
click to toggle source
# File lib/elasticsearch/api/response/renderers/base_renderer.rb, line 54 def value(str) ansi(str, :green) end
wrap_paren(string)
click to toggle source
# File lib/elasticsearch/api/response/renderers/base_renderer.rb, line 58 def wrap_paren(string) if string.start_with?("(") && string.end_with?(")") string else "(" + string + ")" end end