class Codat::Models::FinancialSheet

Constants

DEFAULT_PERIODS_TO_COMPARE

Default number of periods to compare

DEFAULT_PERIOD_LENGTH

Default period length (months)

Attributes

reports[R]

Public Class Methods

build_query(params) click to toggle source
# File lib/codat/models/financial_sheet.rb, line 44
def self.build_query(params)
  options = params.dup

  query = {
    periodLength: options.fetch(:period_length, DEFAULT_PERIOD_LENGTH),
    periodsToCompare: options.fetch(:periods_to_compare, DEFAULT_PERIODS_TO_COMPARE)
  }

  options = options.map { |key, value| [Camelizer.transform(key), value] }.to_h

  query.merge(options)
end
endpoint(endpoint = nil) click to toggle source
# File lib/codat/models/financial_sheet.rb, line 63
def self.endpoint(endpoint = nil)
  return @endpoint unless endpoint

  @endpoint = endpoint
end
find(params = {}) click to toggle source

Finds the latest financial sheet for a company. This can be a balance sheet or a profit and loss document.

Params are listed below:

* company_id - the company ID from Codat
* period_length - the number of months to get
* periods_to_compare - how many periods (of period_length size) you want
* start_month (optional) - starting in which month (date)

An ArgumentError is raised unless you provide a :company_id key in the params.

# File lib/codat/models/financial_sheet.rb, line 30
def self.find(params = {})
  company_id = params.dig(:company_id)

  raise ArgumentError, 'please provide company_id' unless company_id

  url = format_url(@endpoint, company_id: company_id.to_s.strip)

  result = get(url, build_query(params))

  return nil unless successful_response?(result)

  new(json: result.body)
end
inherited(other) click to toggle source
# File lib/codat/models/financial_sheet.rb, line 16
def self.inherited(other)
  other.attributes :currency, :most_recent_available_month, :earliest_available_month
end
new(json: {}) click to toggle source
Calls superclass method Codat::BaseModel::new
# File lib/codat/models/financial_sheet.rb, line 69
def initialize(json: {})
  super

  @most_recent_available_month = Date.parse(json.dig(:mostRecentAvailableMonth))
  @earliest_available_month = Date.parse(json.dig(:earliestAvailableMonth))

  reports_json = json.fetch(:reports, {})
  @reports = reports_json.map { |report| self.class.report_class.new(json: report) }
end
report_class(report_class = nil) click to toggle source
# File lib/codat/models/financial_sheet.rb, line 57
def self.report_class(report_class = nil)
  return @report_class unless report_class

  @report_class = report_class
end