Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float/Integer interchangeable #186

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/lunchmoney.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Module
include T::Sig
end

# Add type alias for when Integer and Float can both be used
Number = T.type_alias { T.any(Integer, Float) }

require_relative "lunchmoney/version"
require_relative "lunchmoney/validators"
require_relative "lunchmoney/api"
Expand Down
4 changes: 2 additions & 2 deletions lib/lunchmoney/budget/budget_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def budgets(start_date:, end_date:, currency: nil)
params(
start_date: String,
category_id: Integer,
amount: T.any(Integer, Float),
amount: Number,
currency: T.nilable(String),
).returns(T.any(
T::Hash[Symbol, { category_id: Integer, amount: T.any(Integer, Float), currency: String, start_date: String }],
T::Hash[Symbol, { category_id: Integer, amount: Number, currency: String, start_date: String }],
LunchMoney::Errors,
))
end
Expand Down
9 changes: 6 additions & 3 deletions lib/lunchmoney/budget/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class Config < LunchMoney::DataObject
# API object reference documentation: https://lunchmoney.dev/#config-object

sig { returns(Integer) }
attr_accessor :config_id, :amount, :to_base
attr_accessor :config_id

sig { returns(Number) }
attr_accessor :amount, :to_base

sig { returns(String) }
attr_accessor :cadence, :currency, :auto_suggest
Expand All @@ -16,9 +19,9 @@ class Config < LunchMoney::DataObject
params(
config_id: Integer,
cadence: String,
amount: Integer,
amount: Number,
currency: String,
to_base: Integer,
to_base: Number,
auto_suggest: String,
).void
end
Expand Down
8 changes: 4 additions & 4 deletions lib/lunchmoney/budget/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Data < LunchMoney::DataObject
sig { returns(T.nilable(Integer)) }
attr_accessor :num_transactions

sig { returns(T.nilable(T.any(Integer, Float))) }
sig { returns(T.nilable(Number)) }
attr_accessor :budget_amount, :budget_to_base, :spending_to_base

sig { returns(T.nilable(String)) }
Expand All @@ -20,11 +20,11 @@ class Data < LunchMoney::DataObject

sig do
params(
spending_to_base: T.nilable(T.any(Integer, Float)),
spending_to_base: T.nilable(Number),
num_transactions: T.nilable(Integer),
budget_amount: T.nilable(T.any(Integer, Float)),
budget_amount: T.nilable(Number),
budget_currency: T.nilable(String),
budget_to_base: T.nilable(T.any(Integer, Float)),
budget_to_base: T.nilable(Number),
is_automated: T.nilable(T::Boolean),
).void
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RecurringExpense < RecurringExpenseBase
plaid_account_id: T.nilable(Integer),
asset_id: T.nilable(Integer),
transaction_id: T.nilable(Integer),
to_base: T.nilable(Integer),
to_base: T.nilable(Number),
).void
end
def initialize(cadence:, payee:, amount:, currency:, billing_date:, type:, source:, id:, created_at:,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class RecurringExpenseBase < LunchMoney::DataObject
sig { returns(String) }
attr_accessor :payee, :currency, :amount

sig { returns(T.nilable(Integer)) }
sig { returns(T.nilable(Number)) }
attr_accessor :to_base

sig do
params(
payee: String,
amount: String,
currency: String,
to_base: T.nilable(Integer),
to_base: T.nilable(Number),
).void
end
def initialize(payee:, amount:, currency:, to_base:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ChildTransaction < TransactionBase
date: String,
amount: String,
currency: String,
to_base: T.any(Integer, Float),
to_base: Number,
payee: String,
formatted_date: String,
notes: T.nilable(String),
Expand Down
4 changes: 2 additions & 2 deletions lib/lunchmoney/transactions/transaction/split.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
module LunchMoney
# Object used to split a transaction when updating https://lunchmoney.dev/#update-transaction
class Split < TransactionModificationBase
sig { returns(T.any(Integer, String)) }
sig { returns(T.any(Number, String)) }
attr_accessor :amount

sig do
params(
amount: T.any(Integer, String),
amount: T.any(Number, String),
payee: T.nilable(String),
date: T.nilable(String),
category_id: T.nilable(Integer),
Expand Down
2 changes: 1 addition & 1 deletion lib/lunchmoney/transactions/transaction/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Transaction < TransactionBase
date: String,
amount: String,
currency: String,
to_base: T.any(Integer, Float),
to_base: Number,
payee: String,
is_income: T::Boolean,
exclude_from_budget: T::Boolean,
Expand Down
4 changes: 2 additions & 2 deletions lib/lunchmoney/transactions/transaction/transaction_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TransactionBase < LunchMoney::DataObject
sig { returns(Integer) }
attr_accessor :id

sig { returns(T.any(Integer, Float)) }
sig { returns(Number) }
attr_accessor :to_base

sig { returns(T.nilable(Integer)) }
Expand All @@ -28,7 +28,7 @@ class TransactionBase < LunchMoney::DataObject
date: String,
amount: String,
currency: String,
to_base: T.any(Integer, Float),
to_base: Number,
payee: String,
notes: T.nilable(String),
asset_id: T.nilable(Integer),
Expand Down