class AppEarnings::GooglePlay::PlayReport
Represents the report.
Public Class Methods
new(name, transactions)
click to toggle source
# File lib/app_earnings/google_play/play_report.rb, line 6 def initialize(name, transactions) extract_amount(name, transactions) unless transactions_from_product.first.nil? @description = transactions_from_product.first[:product_title] end end
Public Instance Methods
amount_from_transactions(transactions)
click to toggle source
It sums up to all available amounts, but it takes just the first one. As it’s usually just one.
# File lib/app_earnings/google_play/play_report.rb, line 15 def amount_from_transactions(transactions) all_currencies = transactions.reduce({}) do |sum, transaction| currency = transaction[:merchant_currency] sum[currency] ||= 0.0 sum[currency] += transaction[:amount_merchant_currency].to_f sum end.first { currency: all_currencies.first, amount: all_currencies.last.round(2) } end