Sha256: 3c5d603fb649a6c50fcdfd170bedee6b141be21320e62ef36c149d62121504f8

Contents?: true

Size: 1.19 KB

Versions: 89

Compression:

Stored size: 1.19 KB

Contents

# encoding: utf-8

module EvalHelper
  # create set variables logic strings, for eval
  #
  # ==== Examples
  #
  # set string variables case
  #
  #   class EvalHelperSetVariablesTest
  #     include EvalHelper
  #
  #     def hoge(variables)
  #       set_variables_code(variables)
  #     end
  #   end
  #
  #   variables = [
  #     {
  #       name: 'name1',
  #       value: '"value1"',
  #     },
  #     {
  #       name: 'name2',
  #       value: '"value2"',
  #     },
  #   ]
  #   EvalHelperSetVariablesTest.new.hoge(variables)
  #
  # return
  #
  #   name1 = "value1"
  #   name2 = "value2"
  #
  def set_variables_code(variables)
    fail TypeError, "invalid type #{variables.class}. you have to use Array" unless variables.is_a? Array
    variables.reduce([]) do |ret, variable|
      fail TypeError, "invalid type #{variable.class}. you have to use Hash" unless variable.is_a? Hash
      fail TypeError, 'invalid hash. you have to set Hash[:name]' if variable[:name].nil?
      fail TypeError, 'invalid hash. you have to set Hash[:value]' if variable[:value].nil?
      ret << "#{variable[:name]} = #{variable[:value]}"
      ret
    end.join("\n")
  end
end

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.150 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.149 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.148 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.147 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.146 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.145 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.144 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.143 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.142 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.141 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.140 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.139 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.138 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.137 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.136 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.135 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.134 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.133 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.132 lib/eval_helper/set_variables_code.rb
tbpgr_utils-0.0.131 lib/eval_helper/set_variables_code.rb