class LazyFuncGeneratorSetting

Attributes

envname[RW]
func_name[RW]
libname[RW]
main_arg_and_how_to_treat[RW]
plot_opt[RW]
print_opt[RW]
runtime_args[RW]
store_result[RW]

Public Class Methods

new() click to toggle source
# File lib/statsailr/block_to_r/sts_lazy_func_gen.rb, line 102
def initialize
  @libname = nil
  @envname = nil
  @func_name = nil

  @main_arg_and_how_to_treat = nil
  @runtime_args = nil

  @store_result = true
  @print_opt = nil
  @plot_opt = nil
end

Public Instance Methods

create_func_arg_hash( main_arg, opt_args ) click to toggle source
# File lib/statsailr/block_to_r/sts_lazy_func_gen.rb, line 115
def create_func_arg_hash( main_arg, opt_args )
  if ! @main_arg_and_how_to_treat.nil?
    main_arg_name, how_to_treat, allow_nil = @main_arg_and_how_to_treat
  else
    main_arg_name, how_to_treat, allow_nil = [nil, nil, nil]
  end
  runtime_args = @runtime_args

  if( ! main_arg_name.nil? )
    if( ! main_arg.empty? )
      if( how_to_treat.to_s =~ /^read/ )
        r_main_arg_hash = {main_arg_name => self.send( how_to_treat, main_arg)  }
      else
        raise "String element that specifies how_to_treat should start from 'read_'"
      end
    elsif allow_nil.to_s == "allow_nil"
      r_main_arg_hash = {}
    else
      raise "main_arg needs needs to be specified or setting.main_arg_and_how_to_treat needs to allow nil"
    end
  else
    r_main_arg_hash = {}
  end

  if( ! opt_args.nil? )
    r_opt_arg_hash = convert_args_to_r_args( opt_args )
  else
    r_opt_arg_hash = {}
  end

  if( !runtime_args.nil?)
    raise "rumtime_args needs to be Hash" if ! runtime_args.is_a?( Hash )
  else
    runtime_args = {}
  end

  r_args = {}
  r_args.merge!( runtime_args )
  r_args.merge!( r_opt_arg_hash )
  r_args.merge!( r_main_arg_hash )
  # The latter hashes have higher priority

  return r_args
end

Private Instance Methods

convert_args_to_r_args( hash ) click to toggle source
# File lib/statsailr/block_to_r/sts_lazy_func_gen.rb, line 161
def convert_args_to_r_args( hash )
  r_hash = {}
  hash.each(){|key, value|
    if value.is_a?(Hash) && value["type"] == :func
      case value["fname"]
      when "param"
        raise "function for " + value["fname"] + " should have one argument." if value["fargs"].size > 1
        r_hash[key] = param(value["fargs"][0].to_s)
      when "result"
        raise "function for " + value["fname"] + " should have one argument." if value["fargs"].size > 1
        r_hash[key] = result(value["fargs"][0].to_s)
      else
        raise "unknown function name in optional argument: " + value.fname
      end
    elsif value.is_a?(Array)
      r_hash[key] = RBridge::convert_to_r_object(value)
    else
      r_hash[key] = RBridge::convert_to_r_object(value)
    end
  }
  return r_hash
end