class BaseOperators::BaseDSLOperators

Attributes

page[R]

Public Instance Methods

api_key(key) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 16
def api_key(key)
  @api_key = key
  self
end
fetch_info() click to toggle source
# File lib/dsl/operators/base_operators.rb, line 132
def fetch_info
  exit(0) if @error

  response = Net::HTTP.get(URI.parse(@path + "?uid=#{@uid}"))

  @info = JSON.parse(response)

  @info[@tricorder.to_s].each_key do |key,val|
    @info[@tricorder.to_s].compact!
    @info[@tricorder.to_s].delete_if { |_k, v| v == false }
    if @info[@tricorder.to_s][key].is_a?(Array)
      @info[@tricorder.to_s][key].each_with_index do |_, index|
        @info[@tricorder.to_s][key][index].compact!
        @info[@tricorder.to_s][key][index].delete_if { |_k, v| v == false }
      end
    end
  end
end
get_result_number(num) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 104
def get_result_number(num)
  exit(0) if @error

  begin
    @result = @results[num - 1]
    set_uid(@result['uid'])
  rescue
    ap "No results found!"
    @error = true
  end

  self
end
humanized_tricorder_name() click to toggle source
# File lib/dsl/operators/base_operators.rb, line 202
def humanized_tricorder_name
  exit(0) if @error

  init_error_messages

  @tricorder.to_s.split('_').map(&:capitalize).join(' ')
end
init_error_messages() click to toggle source
# File lib/dsl/operators/base_operators.rb, line 26
def init_error_messages
  if @tricorder.nil? || !Tricorders::TRICORDERS.include?(@tricorder)
    ap "Invalid Tricorder Name! #{@tricorder}"
    ap "Set the correct tricorder via 'set_tricorder(name)'"
    ap "Tricorders can either be #{Tricorders::TRICORDERS}"
    @error = true
  end

  if @subject.nil?
    ap 'No Subject Defined!'
    ap "Set a subject via 'set_subject(name)'"
    @error = true
  end

  exit(0) if @error
end
log(message, options = {}) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 54
def log(message, options = {})
  return unless options[:verbose] || @verbose

  if options[:pager]
    self.send(options[:pager], message)
  else
    ap(message)
  end
end
merge_results() click to toggle source
# File lib/dsl/operators/base_operators.rb, line 97
def merge_results
  exit(0) if @error

  @results = @results.inject(:merge)
  self
end
no_logging() click to toggle source
# File lib/dsl/operators/base_operators.rb, line 43
def no_logging
  @verbose = false
  self
end
params() click to toggle source
# File lib/dsl/operators/base_operators.rb, line 73
def params
  {
    apiKey: @api_key,
    pageSize: 1000
  }
end
preprocessor(*preprocessors) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 48
def preprocessor(*preprocessors)
  @preprocessors = preprocessors.flatten

  self
end
print_all_info() click to toggle source
print_all_results() click to toggle source
print_info(*fields) click to toggle source
print_only_once() click to toggle source
print_result() click to toggle source
printer(object) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 210
def printer(object)
  exit(0) if @error

  init_error_messages

  @object = object

  if object.empty?
    ap "No info found!"
  else
    if @preprocessors
      @preprocessors.each do |preprocessor|
        self.send(preprocessor.to_sym) unless self.instance_variable_get("@#{preprocessor}".to_sym)
      end
    else
      print_object
    end
  end
end
search_locations(*tricorders) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 87
def search_locations(*tricorders)
  exit(0) if @error

  tricorders.flatten.each do |location|
    self.send("search_#{location.to_s}".to_sym)
  end

  self
end
set_collection(collection) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 80
def set_collection(collection)
  exit(0) if @error

  @collection = collection
  self
end
set_format(type) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 151
def set_format(type)
  formats = [:raw, :plain, :json, :html]

  if formats.include?(type.to_sym)
    @format = type.to_sym
  else
    ap "Invalid format #{@format}. Valid formats are #{formats.join(', ')}"
    @error = true
  end

  self
end
set_path(path) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 64
def set_path(path)
  @path = path
  self
end
set_storedir(path) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 69
def set_storedir(path)
  @storedir = path
end
set_subject(name) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 10
def set_subject(name)
  @subject = name

  self
end
set_tricorder(name) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 21
def set_tricorder(name)
  @tricorder = name.to_sym
  self
end
set_uid(uid) click to toggle source
# File lib/dsl/operators/base_operators.rb, line 118
def set_uid(uid)
  exit(0) if @error

  @uid = uid

  self
end