Sha256: a88d6ee5a2e9c41e861657d6caaf82c408a0316bd371b5eb62719ae152d65b35

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'companies_house_hub/base_model'
require 'companies_house_hub/models/address'
require 'companies_house_hub/models/filing_history'

module CompaniesHouseHub
  class Company < BaseModel
    SEARCH_PATH = '/search'
    FIND_PATH = '/company/:company_number'

    attr_reader :number, :name, :created_at, :address

    def self.search(name, per_page:, start:)
      options = { q: name, items_per_page: per_page, start_index: start }

      result = get(SEARCH_PATH, options)

      result.body.each { |company_json| new(company_json) }
    end

    def self.find(company_number, params = {})
      url = format_url(FIND_PATH, company_number: company_number.to_s)

      result = get(url, params)

      new(result.body)
    end

    def initialize(json = {})
      @number = json.fetch(:company_number)
      @has_been_liquidated = json.fetch(:has_been_liquidated)
      @jurisdiction = json.fetch(:jurisdiction)
      @name = json.fetch(:company_name)
      @created_at = json.fetch(:date_of_creation)
      @address = Address.new(json.fetch(:registered_office_address))
      @status = json.fetch(:company_status)
    end

    def filing_histories
      FilingHistory.all(company_number: @number)
    end

    def full_address
      @address.full
    end

    def active?
      @status == 'active'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
companies_house_hub-0.0.4 lib/companies_house_hub/models/company.rb
companies_house_hub-0.0.3 lib/companies_house_hub/models/company.rb
companies_house_hub-0.0.2 lib/companies_house_hub/models/company.rb
companies_house_hub-0.0.1 lib/companies_house_hub/models/company.rb