Class: RegistersClient::RegisterClient

Inherits:
Object
  • Object
show all
Defined in:
lib/register_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(register_url, data_store, page_size, options = {}) ⇒ RegisterClient

Returns a new instance of RegisterClient.



6
7
8
9
10
11
12
13
# File 'lib/register_client.rb', line 6

def initialize(register_url, data_store, page_size, options = {})
  @register_url = register_url
  @data_store = data_store
  @page_size = page_size
  @options = options

  refresh_data
end

Instance Method Details

#get_current_recordsObject



70
71
72
# File 'lib/register_client.rb', line 70

def get_current_records
  RecordCollection.new(get_records.select { |record| !record.item.has_end_date }, @page_size)
end

#get_custodianObject



54
55
56
# File 'lib/register_client.rb', line 54

def get_custodian
  .select { |record| record.entry.key == 'custodian'}.first
end

#get_entries(since_entry_number = 0) ⇒ Object



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

def get_entries(since_entry_number = 0)
  EntryCollection.new(get_entries_subset_for_entry_type(since_entry_number, :user), @page_size)
end

#get_entry(entry_number) ⇒ Object



23
24
25
# File 'lib/register_client.rb', line 23

def get_entry(entry_number)
  @data_store.get_entry(:user, entry_number)
end

#get_expired_recordsObject



74
75
76
# File 'lib/register_client.rb', line 74

def get_expired_records
  RecordCollection.new(get_records.select { |record| record.item.has_end_date }, @page_size)
end

#get_field_definitionsObject



43
44
45
46
47
48
# File 'lib/register_client.rb', line 43

def get_field_definitions
  ordered_fields = get_register_definition.item.value['fields']
  ordered_records = ordered_fields.map { |f| .find { |record| record.entry.key == "field:#{f}" } }
  @field_definitions ||= RecordCollection.new(ordered_records, @page_size)
  @field_definitions
end

#get_item(item_hash) ⇒ Object



15
16
17
# File 'lib/register_client.rb', line 15

def get_item(item_hash)
  @data_store.get_item(item_hash)
end

#get_itemsObject



19
20
21
# File 'lib/register_client.rb', line 19

def get_items
  @data_store.get_items
end

#get_metadata_recordsObject



39
40
41
# File 'lib/register_client.rb', line 39

def 
  @data_store.get_records(:system)
end

#get_metadata_records_with_history(since_entry_number = 0) ⇒ Object



64
65
66
67
68
# File 'lib/register_client.rb', line 64

def (since_entry_number = 0)
   = get_records_with_history_for_entry_type(since_entry_number, :system)

  RecordMapCollection.new(, @page_size)
end

#get_record(key) ⇒ Object



31
32
33
# File 'lib/register_client.rb', line 31

def get_record(key)
  @data_store.get_record(:user, key)
end

#get_recordsObject



35
36
37
# File 'lib/register_client.rb', line 35

def get_records
  @data_store.get_records(:user)
end

#get_records_with_history(since_entry_number = 0) ⇒ Object



58
59
60
61
62
# File 'lib/register_client.rb', line 58

def get_records_with_history(since_entry_number = 0)
  records_with_history = get_records_with_history_for_entry_type(since_entry_number, :user)

  RecordMapCollection.new(records_with_history, @page_size)
end

#get_register_definitionObject



50
51
52
# File 'lib/register_client.rb', line 50

def get_register_definition
  .select { |record| record.entry.key.start_with?('register:') }.first
end

#refresh_dataObject



78
79
80
81
82
# File 'lib/register_client.rb', line 78

def refresh_data
  user_entry_number = @data_store.get_latest_entry_number(:user)
  rsf = download_rsf(user_entry_number)
  update_data_from_rsf(rsf, user_entry_number, @data_store)
end