Sha256: ee7fe6a5d62d87ba958eec1f8bfab14d829cb0cc70ed1de96709e970d039d237

Contents?: true

Size: 833 Bytes

Versions: 2

Compression:

Stored size: 833 Bytes

Contents

# coding: utf-8
require "ansi/code"

module Abak::Flow
  class Inspector
    def initialize(options = Hash.new)
      @objects = Array.new
      @call_method = options.fetch(:call_method)
      @collect_attribute = options.fetch(:collect_attribute)
    end

    def examine(*args)
      @objects = args
      @fail = @objects.map { |x| x.send(@call_method) }.any? { |x| not !!x }

      self
    end

    def output
      @objects.map do |object|
        next if object.send(@collect_attribute).empty?

        info = ""
        object.send(@collect_attribute).each_with_index do |inf, idx|
          info << "\n  #{idx + 1}. #{inf}"
        end

        "#{Manager.locale.name(object)}#{info}"
      end * "\n"
    end

    def on_fail(&block)
      block.call(self) if @fail
    end
  end # class Inspector
end # module Abak::Flow

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
abak-flow-1.1.1 lib/abak-flow/inspector.rb
abak-flow-1.1.0 lib/abak-flow/inspector.rb