Class: ExplanatoryNotesFile

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/explanatory_notes_file.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(paths) ⇒ Object


16
17
18
19
20
# File 'app/models/explanatory_notes_file.rb', line 16

def load paths
  paths.each do |file_path|
    find_or_create_by_path file_path
  end
end

Instance Method Details

#get_bill_id(bill_name) ⇒ Object


71
72
73
74
75
76
77
78
# File 'app/models/explanatory_notes_file.rb', line 71

def get_bill_id bill_name
  bill = Bill.find_by_name(bill_name)
  if bill.nil?
    nil
  else
    bill.id
  end
end

#get_bill_name(xml) ⇒ Object


66
67
68
69
# File 'app/models/explanatory_notes_file.rb', line 66

def get_bill_name xml
  doc = Hpricot.XML(xml)
  (doc/'BillInfo/Title').inner_text
end

#get_clause_ranges(xml) ⇒ Object


58
59
60
61
62
63
64
# File 'app/models/explanatory_notes_file.rb', line 58

def get_clause_ranges xml
  doc = Hpricot.XML(xml)
  clause_ranges = (doc/'ClauseRange')
  clause_ranges.collect do |node|
    [node['start'], node['end'], node.inner_text, node['SerialNumber']]
  end
end

#get_clauses(xml) ⇒ Object


42
43
44
45
46
47
48
# File 'app/models/explanatory_notes_file.rb', line 42

def get_clauses xml
  doc = Hpricot.XML(xml)
  clauses = (doc/'Clause')
  clauses.collect do |node|
    [node['Number'], node.inner_text, node['SerialNumber']]
  end
end

#get_schedules(xml) ⇒ Object


50
51
52
53
54
55
56
# File 'app/models/explanatory_notes_file.rb', line 50

def get_schedules xml
  doc = Hpricot.XML(xml)
  clauses = (doc/'Schedule')
  clauses.collect do |node|
    [node['Number'], node.inner_text, node['SerialNumber']]
  end
end

#load_notesObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/explanatory_notes_file.rb', line 23

def load_notes
  xml = ExplanatoryNotesParser.parse(path)

  clauses = get_clauses(xml)
  clauses.each do |data|
    NoteByClause.create!(:clause_number => data[0], :note_text => data[1], :serial_number => data[2].to_i, :bill_id => self.bill_id, :explanatory_notes_file_id => self.id)
  end

  schedules = get_schedules(xml)
  schedules.each do |data|
    NoteBySchedule.create!(:schedule_number => data[0], :note_text => data[1], :serial_number => data[2].to_i, :bill_id => self.bill_id, :explanatory_notes_file_id => self.id)
  end

  clause_ranges = get_clause_ranges(xml)
  clause_ranges.each do |data|
    NoteRangeByClause.create!(:clause_number => data[0], :note_text => data[2], :serial_number => data[3].to_i, :range_end => data[1], :bill_id => self.bill_id, :explanatory_notes_file_id => self.id)
  end
end