Module: OpencBot::CompanyFetcherBot

Includes:
OpencBot, Helpers::AlphaSearch, Helpers::IncrementalSearch
Included in:
MyModule
Defined in:
lib/openc_bot/company_fetcher_bot.rb

Constant Summary

Constants included from Helpers::RegisterMethods

Helpers::RegisterMethods::MAX_BUSY_RETRIES, Helpers::RegisterMethods::MAX_STALE_COUNT

Constants included from OpencBot

VERSION

Instance Method Summary collapse

Methods included from Helpers::AlphaSearch

#alpha_terms, #each_search_term, #fetch_data_via_alpha_search, #get_results_and_extract_data_for, #letters_and_numbers, #numbers_of_chars_in_search, #search_for_entities_for_term

Methods included from Helpers::RegisterMethods

#computed_registry_url, #datum_exists?, #default_stale_count, #export_data, #fetch_data, #fetch_registry_page, #get_raw_data, #post_process, #prepare_and_save_data, #raise_when_saving_invalid_record, #raw_data_file_location, #registry_url, #registry_url_from_db, #save_raw_data, #stale_entry_uids, #update_datum, #update_stale, #use_alpha_search, #validate_datum

Methods included from Helpers::IncrementalSearch

#entity_uid_prefixes, #entity_uid_suffixes, #fetch_data_via_incremental_search, #highest_entry_uid_result, #highest_entry_uids, #increment_number, #incremental_rewind_count, #incremental_search, #max_failed_count

Methods included from OpencBot

#db_location, #db_name, #export, extended, #insert_or_update, #root_directory, #save_data, #save_run_report, #spotcheck, #sqlite_busy_timeout, #sqlite_magic_connection, #table_summary, #unlock_database, #verbose?

Methods included from Helpers::Text

#normalise_utf8_spaces, #strip_all_spaces

Instance Method Details

#fetch_datum(company_number) ⇒ Object

This is called by #update_datum



17
18
19
20
# File 'lib/openc_bot/company_fetcher_bot.rb', line 17

def fetch_datum(company_number)
  company_page = fetch_registry_page(company_number)
  {:company_page => company_page}
end

#inferred_jurisdiction_codeObject



22
23
24
25
# File 'lib/openc_bot/company_fetcher_bot.rb', line 22

def inferred_jurisdiction_code
  poss_j_code = self.name.sub(/CompaniesFetcher/,'').underscore
  poss_j_code[/^[a-z]{2}$|^[a-z]{2}_[a-z]{2}$/]
end

#primary_key_nameObject



27
28
29
# File 'lib/openc_bot/company_fetcher_bot.rb', line 27

def primary_key_name
  :company_number
end

#save_entity(entity_info) ⇒ Object

This overrides default #save_entity (defined in RegisterMethods) and adds the inferred jurisdiction_code, unless it is overridden in entity_info



33
34
35
36
37
# File 'lib/openc_bot/company_fetcher_bot.rb', line 33

def save_entity(entity_info)
  return if entity_info.blank?
  default_options = {:jurisdiction_code => inferred_jurisdiction_code}
  super(default_options.merge(entity_info))
end

#save_entity!(entity_info) ⇒ Object



39
40
41
42
43
# File 'lib/openc_bot/company_fetcher_bot.rb', line 39

def save_entity!(entity_info)
  return if entity_info.blank?
  default_options = {:jurisdiction_code => inferred_jurisdiction_code}
  super(default_options.merge(entity_info))
end

#schema_nameObject



45
46
47
# File 'lib/openc_bot/company_fetcher_bot.rb', line 45

def schema_name
  super || 'company-schema'
end

#update_data(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/openc_bot/company_fetcher_bot.rb', line 49

def update_data(options={})
  fetch_data
  update_stale
  send_run_report
rescue Exception => e
  send_error_report(e)
  raise e
end