class CompaniesHouseHub::FilingHistory
Constants
- DEFAULT_PER_PAGE
- DOCUMENT_URL
- FIND_PATH
- LEGACY_DOC_DESCRIPTION
Attributes
action_date[R]
barcode[R]
date[R]
description[R]
description_values[R]
links[R]
name[R]
type[R]
Public Class Methods
all(options = {})
click to toggle source
# File lib/companies_house_hub/models/filing_history.rb, line 16 def self.all(options = {}) options[:items_per_page] ||= DEFAULT_PER_PAGE company_number = options.delete(:company_number) result = get(format_url(FIND_PATH, company_number: company_number), options) items = result.body.dig(:items) || [] return [] unless items.any? # Get all items and create a new history. If the description is 'legacy' then we can safely # ignore that document. filing_histories = items.map do |filing_json| next if filing_json.dig(:description) == LEGACY_DOC_DESCRIPTION new(filing_json, company_number) end filing_histories.compact end
new(json = {}, company_number = nil)
click to toggle source
# File lib/companies_house_hub/models/filing_history.rb, line 38 def initialize(json = {}, company_number = nil) @description = json.dig(:description) @action_date = json.dig(:action_date) @date = json.dig(:date) @type = json.dig(:type) @links = json.dig(:links) @transaction_id = json.dig(:transaction_id) # helps on barcode generation @barcode = json.dig(:barcode) || generate_barcode @description_values = json.dig(:description_values) @company_number = company_number end
Public Instance Methods
formatted_name()
click to toggle source
# File lib/companies_house_hub/models/filing_history.rb, line 50 def formatted_name FilingHistoryFormatter.new(self).formatted end
url(format = 'pdf')
click to toggle source
# File lib/companies_house_hub/models/filing_history.rb, line 54 def url(format = 'pdf') return unless @links[:document_metadata] file_path = @links[:self] || build_file_path return unless file_path document_path = "#{file_path}/document?format=#{format}" URI.join(DOCUMENT_URL, document_path).to_s end
Private Instance Methods
build_file_path()
click to toggle source
# File lib/companies_house_hub/models/filing_history.rb, line 77 def build_file_path required = [@company_number, @transaction_id].all? { |val| val && !val.empty? } "/company/#{@company_number}/filing-history/#{@transaction_id}" if required end
generate_barcode()
click to toggle source
Sometimes the barcode comes as nil for some reason so we generate one based on the url. If the URL is also not defined then we hope for the best and use other variables.
# File lib/companies_house_hub/models/filing_history.rb, line 70 def generate_barcode string = @links[:self] if @links string ||= [@description, @type, @transaction_id].compact.join Digest::SHA1.hexdigest(string)[0..6].upcase end