Class: PeopleUpdater
Overview
handles people.csv and splits out family data for FamilyUpdater
Instance Attribute Summary
Attributes inherited from UpdateAgent
#attributes, #create, #data, #update
Instance Method Summary
collapse
Methods inherited from UpdateAgent
#check_for_invalid_columns, #confirm, #data_by_id, #ids, #legacy_ids, #present_record, #read_from_file, #resource
Constructor Details
split out family data and create a new FamilyUpdater
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/updateagent/updaters/people_updater.rb', line 6
def initialize(filename)
super(filename)
if defined?(USE_CONVERTER)
converter = Kernel.const_get(USE_CONVERTER + 'Converter').new
@data = converter.convert(@data.clone)
@attributes = @data.first.keys
end
person_data = []
family_data = {}
@data.each_with_index do |row, index|
person, family = split_change_hash(row)
if existing_family = family_data[family['legacy_id']]
person['family'] = existing_family
person_data << person
else
person['family'] = family
person_data << person
family_data[family['legacy_id']] = family
end
print "splitting family record #{index+1}\r"
end
puts
@data = person_data
@attributes.reject! { |a| a =~ /^family_/ and a != 'family_id' }
@family_agent = FamilyUpdater.new(family_data.values)
end
|
Instance Method Details
#compare(force = false) ⇒ Object
37
38
39
40
|
# File 'lib/updateagent/updaters/people_updater.rb', line 37
def compare(force=false)
@family_agent.compare(force)
super(force)
end
|
#has_work? ⇒ Boolean
42
43
44
|
# File 'lib/updateagent/updaters/people_updater.rb', line 42
def has_work?
@family_agent.has_work? or super
end
|
#name_for(row) ⇒ Object
33
34
35
|
# File 'lib/updateagent/updaters/people_updater.rb', line 33
def name_for(row)
"#{row['first_name']} #{row['last_name']}"
end
|
#present ⇒ Object
46
47
48
49
|
# File 'lib/updateagent/updaters/people_updater.rb', line 46
def present
@family_agent.present if @family_agent.has_work?
super
end
|
#push ⇒ Object
51
52
53
54
|
# File 'lib/updateagent/updaters/people_updater.rb', line 51
def push
@family_agent.push
super
end
|