<commit_before># -*- encoding : utf-8 -*-
# Deal 関係のユーティリティメソッド

# 口座idを取得するためのユーティリティ fixture名またはレコードを渡す
def to_account_id(value)
  case value
  when Symbol
    Fixtures.identify(value)
  when ActiveRecord::Base
    value.id
  else
    value
  end
end

# 単純明細記入の作成
def new_simple_deal(month, day, from, to, amount, year = 2008)
  d = Deal::General.new(:summary => "#{month}/#{day}の買い物",
    :debtor_entries_attributes => [:account_id => to_account_id(to), :amount => amount],
    :creditor_entries_attributes => [:account_id => to_account_id(from), :amount => amount * -1],
    :date => Date.new(year, month, day))
  to_account = Account::Base.find(to_account_id(to))
  d.user_id = to_account.user_id
  d
end

# 複数明細記入の作成
# debtors {account_id => amout, account_id => amount} のように記述
# [account_id, amount]の配列でも可
def new_complex_deal(month, day, debtors, creditors, options = {})
  summary = options[:summary] || "#{month}/#{day}の記入"
  date = Date.new(options[:year] || 2010, month, day)

  deal = Deal::General.new(:summary => summary, :summary_mode => 'unify', :date => date,
    :debtor_entries_attributes => debtors.map{|key, value| {:account_id => (key.kind_of?(Symbol) ? Fixtures.identify(key) : key), :amount => value}}.each_with_index{|e, i| e[:line_number] = i},
    :creditor_entries_attributes => creditors.map{|key, value| {:account_id => (key.kind_of?(Symbol) ? Fixtures.identify(key) : key), :amount => value}}.each_with_index{|e, i| e[:line_number] = i}
  )

  key = debtors.keys.first
  account_id = key.kind_of?(Symbol) ? Fixtures.identify(key) : key
  account = Account::Base.find_by_id(account_id)
  raise "no account" unless account
  deal.user_id = account.user_id
  deal
end<commit_msg>Support array in new_complex_deal.<commit_after># -*- encoding : utf-8 -*-
# Deal 関係のユーティリティメソッド

# 口座idを取得するためのユーティリティ fixture名またはレコードを渡す
def to_account_id(value)
  case value
  when Symbol
    Fixtures.identify(value)
  when ActiveRecord::Base
    value.id
  else
    value
  end
end

# 単純明細記入の作成
def new_simple_deal(month, day, from, to, amount, year = 2008)
  d = Deal::General.new(:summary => "#{month}/#{day}の買い物",
    :debtor_entries_attributes => [:account_id => to_account_id(to), :amount => amount],
    :creditor_entries_attributes => [:account_id => to_account_id(from), :amount => amount * -1],
    :date => Date.new(year, month, day))
  to_account = Account::Base.find(to_account_id(to))
  d.user_id = to_account.user_id
  d
end

# 複数明細記入の作成
# debtors {account_id => amout, account_id => amount} のように記述
# [account_id, amount]の配列でも可
def new_complex_deal(month, day, debtors, creditors, options = {})
  summary = options[:summary] || "#{month}/#{day}の記入"
  date = Date.new(options[:year] || 2010, month, day)

  deal = Deal::General.new(:summary => summary, :summary_mode => 'unify', :date => date,
    :debtor_entries_attributes => debtors.map{|key, value| {:account_id => (key.kind_of?(Symbol) ? Fixtures.identify(key) : key), :amount => value}}.each_with_index{|e, i| e[:line_number] = i},
    :creditor_entries_attributes => creditors.map{|key, value| {:account_id => (key.kind_of?(Symbol) ? Fixtures.identify(key) : key), :amount => value}}.each_with_index{|e, i| e[:line_number] = i}
  )

  key = debtors.respond_to?(:keys) ? debtors.keys.first : debtors.first.first
  account_id = key.kind_of?(Symbol) ? Fixtures.identify(key) : key
  account = Account::Base.find_by_id(account_id)
  raise "no account" unless account
  deal.user_id = account.user_id
  deal
end
{'fraction_non_alphanumeric': 0.1588302752293578, 'fraction_numerical': 0.005733944954128441, 'mean_word_length': 5.01551724137931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '326188', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1353, 'n_words': 254}