class CompaniesHouseHub::Company
Constants
- FIND_PATH
- SEARCH_PATH
Attributes
accounts[R]
address[R]
company_name[R]
company_number[R]
company_status[R]
confirmation_statement[R]
created_at[R]
date_of_creation[R]
full_address[R]
has_been_liquidated[R]
jurisdiction[R]
name[R]
number[R]
raw_json[R]
status[R]
type[R]
Public Class Methods
find(company_number, params = {})
click to toggle source
# File lib/companies_house_hub/models/company.rb, line 38 def self.find(company_number, params = {}) url = format_url(FIND_PATH, company_number: company_number.to_s.strip) result = get(url, params) return if result.status == 404 new(result.body) end
new(json = {})
click to toggle source
# File lib/companies_house_hub/models/company.rb, line 48 def initialize(json = {}) @raw_json = json @number = json.dig(:company_number) @has_been_liquidated = json.dig(:has_been_liquidated) @jurisdiction = json.dig(:jurisdiction) @name = json.dig(:company_name) || json.dig(:title) @created_at = json.dig(:date_of_creation) @address = Address.new(json.dig(:registered_office_address) || json.dig(:address) || {}) @status = json.dig(:company_status) @type = json.dig(:type) || json.dig(:company_type) @accounts = json.dig(:accounts) @confirmation_statement = json.dig(:confirmation_statement) @full_address = json.fetch(:address_snippet, @address.full) end
search(name, per_page: nil, start: nil)
click to toggle source
# File lib/companies_house_hub/models/company.rb, line 21 def self.search(name, per_page: nil, start: nil) options = { q: name, items_per_page: per_page, start_index: start } result = get(SEARCH_PATH, options) return [] unless result.success? # Get all items and create a new company. If the company has no number we need to ignore it. companies = result.body[:items].map do |company_json| next unless company_json.dig(:company_number) new(company_json) end companies.compact end
Public Instance Methods
active?()
click to toggle source
# File lib/companies_house_hub/models/company.rb, line 71 def active? @status == 'active' end
filing_histories()
click to toggle source
# File lib/companies_house_hub/models/company.rb, line 63 def filing_histories FilingHistory.all(company_number: @number) end
persons()
click to toggle source
# File lib/companies_house_hub/models/company.rb, line 67 def persons Person.all(company_number: @number) end