Module: AppEarnings::Report
- Included in:
- Amazon::AmazonReport, GooglePlay::PlayReport
- Defined in:
- lib/app_earnings/report.rb
Overview
Base class for reports
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#name ⇒ Object
Returns the value of attribute name.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
Class Method Summary collapse
Instance Method Summary collapse
- #extract_amount(name, transactions) ⇒ Object
- #formatted_total_by_products ⇒ Object
- #formatted_transactions_count_by_type ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
- #total_from_in_app_purchases ⇒ Object
- #transactions_by_type ⇒ Object
- #transactions_count_by_type ⇒ Object
- #transactions_from_in_app_purchases ⇒ Object
- #transactions_from_in_app_purchases_by_id_and_name ⇒ Object
- #transactions_from_product ⇒ Object
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
4 5 6 |
# File 'lib/app_earnings/report.rb', line 4 def amount @amount end |
#currency ⇒ Object
Returns the value of attribute currency.
4 5 6 |
# File 'lib/app_earnings/report.rb', line 4 def currency @currency end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/app_earnings/report.rb', line 4 def name @name end |
#transactions ⇒ Object
Returns the value of attribute transactions.
4 5 6 |
# File 'lib/app_earnings/report.rb', line 4 def transactions @transactions end |
Class Method Details
.formatted_amount(currency, amount) ⇒ Object
66 67 68 69 |
# 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 |
Instance Method Details
#extract_amount(name, transactions) ⇒ Object
6 7 8 9 10 11 12 |
# 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 ⇒ Object
58 59 60 61 62 63 64 |
# 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 ⇒ Object
52 53 54 55 56 |
# 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 ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# 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 ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# 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 ⇒ Object
43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
14 15 16 |
# File 'lib/app_earnings/report.rb', line 14 def transactions_by_type transactions.group_by { |transaction| transaction[:transaction_type] } end |
#transactions_count_by_type ⇒ Object
31 32 33 34 35 36 37 |
# 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 ⇒ Object
18 19 20 21 22 |
# 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 ⇒ Object
24 25 26 27 28 29 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/app_earnings/report.rb', line 39 def transactions_from_product transactions - transactions_from_in_app_purchases end |