class Erlash::Base

Attributes

input[R]
opts[R]

Public Class Methods

_display_context() click to toggle source
# File lib/erlash/base.rb, line 16
def _display_context
  defined?(@display_context) ? @display_context : true
end
display_context(arg) click to toggle source
# File lib/erlash/base.rb, line 13
def display_context(arg)
  @display_context = arg
end
new(input = nil, opts = {}) click to toggle source
Calls superclass method
# File lib/erlash/base.rb, line 22
def initialize(input = nil, opts = {})
  @input = input
  @opts = default_opts.merge(opts)
  set_formatter
  super(formatter.to_s)
end
problem(arg = nil, &block) click to toggle source
# File lib/erlash/base.rb, line 4
def problem(arg = nil, &block)
  @problem = block || arg
end
resolution(arg = nil, &block) click to toggle source
# File lib/erlash/base.rb, line 10
def resolution(arg = nil, &block)
  @resolution = block || arg
end
summary(arg = nil, &block) click to toggle source
# File lib/erlash/base.rb, line 7
def summary(arg = nil, &block)
  @summary = block || arg
end

Public Instance Methods

hints?() click to toggle source
# File lib/erlash/base.rb, line 39
def hints?
  !!(problem || summary || resolution)
end
problem() click to toggle source
# File lib/erlash/base.rb, line 29
def problem
  @problem ||= exec_config(self.class.instance_variable_get(:@problem))
end
resolution() click to toggle source
# File lib/erlash/base.rb, line 35
def resolution
  @resolution ||= exec_config(self.class.instance_variable_get(:@resolution))
end
skip?() click to toggle source
# File lib/erlash/base.rb, line 43
def skip?
  false
end
summary() click to toggle source
# File lib/erlash/base.rb, line 32
def summary
  @summary ||= exec_config(self.class.instance_variable_get(:@summary))
end

Private Instance Methods

context() click to toggle source
# File lib/erlash/base.rb, line 75
def context
  @context ||= case input
               when Array
                 Erlash::MainArray.build(input)
               when Hash
                 Erlash::MainHash.build(input)
               else
                 input
               end
end
default_opts() click to toggle source
# File lib/erlash/base.rb, line 58
def default_opts
  {
    display_context: self.class._display_context
  }
end
display_context?() click to toggle source
# File lib/erlash/base.rb, line 63
def display_context?
  opts[:display_context]
end
exec_config(val) click to toggle source
# File lib/erlash/base.rb, line 86
def exec_config(val)
  if val.is_a?(Proc)
    val.call(context)
  else
    val
  end
end
formatter() click to toggle source
# File lib/erlash/base.rb, line 71
def formatter
  @formatter ||= Formatter.new(registry)
end
registry() click to toggle source
# File lib/erlash/base.rb, line 67
def registry
  Erlash.formatters
end
set_formatter() click to toggle source
# File lib/erlash/base.rb, line 49
def set_formatter
  formatter.tap do |f|
    f << Tip.new('Problem:', problem) if problem
    f << Tip.new('Summary:', summary) if summary
    f << Tip.new('Resolution:', resolution) if resolution
    f << Context.new(self, context) if display_context?
  end
end