module AppEarnings::Report
Base class for reports
Attributes
amount[RW]
currency[RW]
name[RW]
transactions[RW]
Public Class Methods
formatted_amount(currency, amount)
click to toggle source
# File lib/app_earnings/report.rb, line 66 def self.formatted_amount(currency, amount) symbol = ISO4217::Currency.from_code(currency).symbol "#{currency} #{symbol}#{sprintf('%.2f', amount)}" end
Public Instance Methods
extract_amount(name, transactions)
click to toggle source
# File lib/app_earnings/report.rb, line 6 def extract_amount(name, transactions) @name = name @transactions = transactions @total_amount = amount_from_transactions(@transactions) @currency = @total_amount[:currency] @amount = @total_amount[:amount] end
formatted_total_by_products()
click to toggle source
# File lib/app_earnings/report.rb, line 58 def formatted_total_by_products total_from_in_app_purchases.sort_by { |product| product[:id] } .map do |app| total_amount = Report.formatted_amount(app[:currency], app[:amount]) "#{app[:id]} - #{app[:name]}: #{total_amount}" end end
formatted_transactions_count_by_type()
click to toggle source
# File lib/app_earnings/report.rb, line 52 def formatted_transactions_count_by_type transactions_count_by_type.sort_by { |name, _| name }.map do |tr| tr.join(': ') end end
to_json()
click to toggle source
# File lib/app_earnings/report.rb, line 71 def to_json { id: @name, name: @description, transactions_types: transactions_count_by_type, total: @amount.round(2), currency: @currency, subtotals: total_from_in_app_purchases } end
to_s()
click to toggle source
# File lib/app_earnings/report.rb, line 82 def to_s %Q(#{@name} #{@description} Transactions: #{formatted_transactions_count_by_type.join(", ")} Total: #{Report.formatted_amount(@currency, @amount)} Sub totals by IAP: #{formatted_total_by_products.join("\n")} ) end
total_from_in_app_purchases()
click to toggle source
# File lib/app_earnings/report.rb, line 43 def total_from_in_app_purchases transactions_from_in_app_purchases_by_id_and_name.map do |iap, tr| { id: iap.first, name: iap.last }.merge(amount_from_transactions(tr)) end end
transactions_by_type()
click to toggle source
# File lib/app_earnings/report.rb, line 14 def transactions_by_type transactions.group_by { |transaction| transaction[:transaction_type] } end
transactions_count_by_type()
click to toggle source
# File lib/app_earnings/report.rb, line 31 def transactions_count_by_type transaction_count = {} transactions_by_type.each do |type, transactions| transaction_count[type] = transactions.length end transaction_count end
transactions_from_in_app_purchases()
click to toggle source
# File lib/app_earnings/report.rb, line 18 def transactions_from_in_app_purchases transactions.reject do |tr| tr[:sku_id].nil? && tr[:vendor_sku].nil? end end
transactions_from_in_app_purchases_by_id_and_name()
click to toggle source
# File lib/app_earnings/report.rb, line 24 def transactions_from_in_app_purchases_by_id_and_name transactions_from_in_app_purchases.group_by do |tr| [tr[:sku_id] || tr[:vendor_sku], tr[:item_name] || tr[:product_title]] end end
transactions_from_product()
click to toggle source
# File lib/app_earnings/report.rb, line 39 def transactions_from_product transactions - transactions_from_in_app_purchases end