Class: Codat::Models::FinancialSheet
- Defined in:
- lib/codat/models/financial_sheet.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_PERIOD_LENGTH =
Default period length (months)
12
- DEFAULT_PERIODS_TO_COMPARE =
Default number of periods to compare
2
Instance Attribute Summary collapse
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
Class Method Summary collapse
- .build_query(params) ⇒ Object
- .endpoint(endpoint = nil) ⇒ Object
-
.find(params = {}) ⇒ Object
Finds the latest financial sheet for a company.
- .inherited(other) ⇒ Object
- .report_class(report_class = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(json: {}) ⇒ FinancialSheet
constructor
A new instance of FinancialSheet.
Methods inherited from BaseModel
attributes, #format_url, format_url, get, #get, post, #post, successful_response?
Constructor Details
#initialize(json: {}) ⇒ FinancialSheet
Returns a new instance of FinancialSheet.
71 72 73 74 75 76 77 78 79 |
# File 'lib/codat/models/financial_sheet.rb', line 71 def initialize(json: {}) super @most_recent_available_month = Date.parse(json[:mostRecentAvailableMonth]) @earliest_available_month = Date.parse(json[:earliestAvailableMonth]) reports_json = json.fetch(:reports, {}) @reports = reports_json.map { |report| self.class.report_class.new(json: report) } end |
Instance Attribute Details
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
14 15 16 |
# File 'lib/codat/models/financial_sheet.rb', line 14 def reports @reports end |
Class Method Details
.build_query(params) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/codat/models/financial_sheet.rb', line 46 def self.build_query(params) = params.dup query = { periodLength: .fetch(:period_length, DEFAULT_PERIOD_LENGTH), periodsToCompare: .fetch(:periods_to_compare, DEFAULT_PERIODS_TO_COMPARE) } = .transform_keys { |key| Camelizer.transform(key) } query.merge() end |
.endpoint(endpoint = nil) ⇒ Object
65 66 67 68 69 |
# File 'lib/codat/models/financial_sheet.rb', line 65 def self.endpoint(endpoint = nil) return @endpoint unless endpoint @endpoint = endpoint end |
.find(params = {}) ⇒ Object
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.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/codat/models/financial_sheet.rb', line 32 def self.find(params = {}) company_id = params[: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) ⇒ Object
16 17 18 19 20 |
# File 'lib/codat/models/financial_sheet.rb', line 16 def self.inherited(other) super other.attributes :currency, :most_recent_available_month, :earliest_available_month end |
.report_class(report_class = nil) ⇒ Object
59 60 61 62 63 |
# File 'lib/codat/models/financial_sheet.rb', line 59 def self.report_class(report_class = nil) return @report_class unless report_class @report_class = report_class end |