air18n 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,9 +33,6 @@ module Air18n
33
33
  end
34
34
  end
35
35
 
36
- COST_PER_WORD_TRANSLATION = 0.07
37
- COST_PER_WORD_VERIFICATION = 0.05
38
-
39
36
  # Provides a complete set of latest translations for specified locales, in nested hash format.
40
37
  # filter_opts are passed to keep_key? for optional filtering, like throwing
41
38
  # away user-generated content.
@@ -132,7 +129,6 @@ module Air18n
132
129
  {}.tap do |activity|
133
130
  activity[:num_translations], activity[:word_count_translations] = translation_word_count(phrase_ids_values_by_type[false])
134
131
  activity[:num_verifications], activity[:word_count_verifications] = translation_word_count(phrase_ids_values_by_type[true])
135
- activity[:payment] = activity[:word_count_translations] * COST_PER_WORD_TRANSLATION + activity[:word_count_verifications] * COST_PER_WORD_VERIFICATION
136
132
  end
137
133
  end
138
134
 
@@ -176,7 +172,7 @@ module Air18n
176
172
  rich_memory.save!
177
173
  end
178
174
 
179
- def self.translator_payment_data
175
+ def self.translator_payment_data(compute_payment_method)
180
176
  today_last_month = 1.month.ago
181
177
  ret = []
182
178
  PhraseTranslation.translator_activity_data(0, :since => 2.months.ago).each do |stats|
@@ -187,7 +183,9 @@ module Air18n
187
183
  stats[:currency] = 'EUR'
188
184
  stats[:is_admin] = user.try(:role_admin?)
189
185
  stats[:is_paid] = !stats[:is_admin] && !fetch_unpaid_nonadmin_translator_list.include?(stats[:user_id])
190
- stats[:usd_amount] = Currency.convert(stats[:activity][:payment], stats[:currency], "USD").round
186
+ payment = compute_payment_method.call(stats[:activity][:word_count_translations], stats[:activity][:word_count_verifications], stats[:user_id], stats[:locale].to_sym)
187
+ stats[:native_amount] = payment
188
+ stats[:usd_amount] = Currency.convert(payment, stats[:currency], "USD").round
191
189
  if stats[:is_paid] && stats[:usd_amount] > 0
192
190
  stats[:description] = "Translator payout "
193
191
  stats[:description] << "for #{Date::MONTHNAMES[today_last_month.month]} #{today_last_month.year}. "
@@ -25,7 +25,9 @@ module Air18n
25
25
  if all_unreviewed_screenshots.empty?
26
26
  nil
27
27
  else
28
- Screenshot.find_by_id(all_unreviewed_screenshots.choice.id)
28
+ # Array#choice was renamed to Array#sample in Ruby 1.9.
29
+ random_sample = all_unreviewed_screenshots.respond_to?(:choice) ? all_unreviewed_screenshots.choice : all_unreviewed_screenshots.sample
30
+ Screenshot.find_by_id(random_sample.id)
29
31
  end
30
32
  end
31
33
 
@@ -1,3 +1,3 @@
1
1
  module Air18n
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/make_gem CHANGED
@@ -1,5 +1,5 @@
1
1
  # Run this to push the new version of the gem to rubygems!
2
- v=0.1.0
2
+ v=0.1.1
3
3
  gem build air18n.gemspec
4
4
  gem push air18n-${v}.gem
5
5
 
@@ -22,59 +22,4 @@ describe Air18n::PhraseTranslation do
22
22
  end
23
23
  end
24
24
 
25
- describe 'compute monthly translator payments' do
26
- before do
27
- # TODO(jason) Stub out User.
28
- # @user1 = FactoryGirl.create(:user)
29
- # @user2 = FactoryGirl.create(:user)
30
- @phrase1 = FactoryGirl.create(:phrase, :value => 'two words')
31
- @phrase2 = FactoryGirl.create(:phrase, :value => 'three long words')
32
- end
33
-
34
- it "should pay for only last month's translation" do
35
- pending "Stub out User class"
36
- without_timestamping_of Air18n::PhraseTranslation do
37
- translation = FactoryGirl.create(:phrase_translation, :phrase => @phrase1, :user => @user1, :created_at => 1.month.ago)
38
- other_phrase_translation = FactoryGirl.create(:phrase_translation, :phrase => @phrase2, :user => @user1, :created_at => 1.month.ago)
39
- other_user_translation = FactoryGirl.create(:phrase_translation, :phrase => @phrase1, :user => @user2, :created_at => 1.month.ago)
40
- older_translation = FactoryGirl.create(:phrase_translation, :phrase => @phrase1, :user => @user1, :created_at => 2.months.ago)
41
-
42
- data = Air18n::PhraseTranslation.translator_payment_data
43
-
44
- data[0].should include(
45
- {:locale => "es", :is_paid => true, :currency => "EUR", :usd_amount => 1, :smart_name => @user1.smart_name, :user_id => @user1.id, :month => 1.month.ago.month, :is_admin => false, :year => 1.month.ago.year })
46
- data[0][:activity].should include(
47
- { :payment => 5 * Air18n::PhraseTranslation::COST_PER_WORD_TRANSLATION, :num_translations => 2, :num_phrases_prev_translated => 1, :word_count_translations => 5 })
48
-
49
- data[1].should include(
50
- { :locale => "es", :is_paid => true, :currency => "EUR", :usd_amount => 0, :smart_name => @user2.smart_name, :user_id => @user2.id, :is_admin => false })
51
- data[1][:activity].should include(
52
- { :payment => 2 * Air18n::PhraseTranslation::COST_PER_WORD_TRANSLATION, :num_translations => 1, :num_phrases_prev_translated => 0, :word_count_translations => 2 })
53
- end
54
- end
55
-
56
- it 'should pay less for verification' do
57
- pending "Stub out User class"
58
- without_timestamping_of Air18n::PhraseTranslation do
59
- translation = FactoryGirl.create(:phrase_translation, :phrase => @phrase1, :user => @user1, :created_at => 1.month.ago)
60
- other_phrase_translation = FactoryGirl.create(:phrase_translation, :phrase => @phrase2, :user => @user1, :created_at => 1.month.ago)
61
- other_user_translation = FactoryGirl.create(:phrase_translation, :phrase => @phrase1, :user => @user2, :created_at => 1.month.ago)
62
- phrase_verification = FactoryGirl.create(:phrase_translation, :phrase => @phrase2, :user => @user2, :is_verification => true, :created_at => 1.month.ago)
63
-
64
-
65
- data = Air18n::PhraseTranslation.translator_payment_data
66
-
67
- data[0].should include(
68
- {:locale => "es", :is_paid => true, :currency => "EUR", :usd_amount => 1, :smart_name => @user1.smart_name, :user_id => @user1.id, :month => 1.month.ago.month, :is_admin => false, :year => 1.month.ago.year })
69
- data[0][:activity].should include(
70
- { :payment => 5 * Air18n::PhraseTranslation::COST_PER_WORD_TRANSLATION, :num_translations => 2, :word_count_translations => 5 })
71
-
72
- data[1].should include(
73
- { :locale => "es", :is_paid => true, :currency => "EUR", :usd_amount => 0, :smart_name => @user2.smart_name, :user_id => @user2.id, :is_admin => false })
74
- data[1][:activity].should include(
75
- { :payment => 2 * Air18n::PhraseTranslation::COST_PER_WORD_TRANSLATION + 3 * Air18n::PhraseTranslation::COST_PER_WORD_VERIFICATION, :num_translations => 1, :num_verifications => 1, :word_count_translations => 2, :word_count_verifications => 3 })
76
- end
77
- end
78
- end
79
-
80
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: air18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-06-23 00:00:00.000000000 Z
16
+ date: 2012-07-05 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: i18n