Commit 94a6ab18 authored by Michael Witrant's avatar Michael Witrant
Browse files

essai differ

parent f4a81181
Amendment <NumAm>1</NumAm> <Amend>Amendment <NumAm>1</NumAm>
<DocAmend>Proposal for a decision</DocAmend> <DocAmend>Proposal for a decision</DocAmend>
<Article>Recital 4</Article> <Article>Recital 4</Article>
......
#!/usr/bin/env ruby #!/usr/bin/env ruby
# Pour lancer le script il faut ruby, rubygems et la gem nokogiri # Pour lancer le script il faut ruby, rubygems et les gems nokogiri et differ
require 'rubygems' require 'rubygems'
require 'nokogiri' require 'nokogiri'
require 'differ'
require 'erb' require 'erb'
data = %w(3 1 2).map { |i| File.read("Amdts_spectre_#{i}.txt") }.join data = %w(3 1 2).map { |i| File.read("Amdts_spectre_#{i}.txt") }.join
...@@ -11,7 +12,7 @@ sections = data.scan(%r(<Amend>.+?</Amend>)m) ...@@ -11,7 +12,7 @@ sections = data.scan(%r(<Amend>.+?</Amend>)m)
Amendment = Struct.new :num, :note, :color, :commission_rows, :amendement_rows, :members, :article Amendment = Struct.new :num, :note, :color, :commission_rows, :amendement_rows, :members, :article
Differ.format = :html
class Amendment class Amendment
Template = ERB.new File.read('template.erb'), nil, '-' Template = ERB.new File.read('template.erb'), nil, '-'
...@@ -19,6 +20,10 @@ class Amendment ...@@ -19,6 +20,10 @@ class Amendment
def format def format
Template.result(binding) Template.result(binding)
end end
def rows
[commission_rows.size, amendement_rows.size].max
end
end end
amendments = sections.map do |xml| amendments = sections.map do |xml|
...@@ -51,13 +56,12 @@ amendments = sections.map do |xml| ...@@ -51,13 +56,12 @@ amendments = sections.map do |xml|
commission_rows = [] commission_rows = []
amendement_rows = [] amendement_rows = []
infos.each_slice(2) do |commission, amendement| infos.each_slice(2) do |commission, amendment|
commission_rows << commission commission = commission.to_s
amendement_rows << amendement amendment = amendment.to_s
end #p [commission, amendment, Differ.diff_by_char(amendment, commission).to_s]
commission_rows << Differ.diff_by_char(commission, amendment).to_s
[commission_rows, amendement_rows].each do |rows| amendement_rows << Differ.diff_by_char(amendment, commission).to_s
rows.delete_if { |row| row.nil? or row.empty? }
end end
members = doc.css('Members').text members = doc.css('Members').text
......
This diff is collapsed.
...@@ -9,11 +9,13 @@ Amendement <%= num %> ...@@ -9,11 +9,13 @@ Amendement <%= num %>
<%= members %> <%= members %>
<br/> <br/>
<%= note %> <%= note %>
<% rows.times do |row| -%>
|- |-
|width="50%"| |width="50%"|
<%= commission_rows.join("\n\n") %> <%= commission_rows[row] %>
|width="50%"| |width="50%"|
<%= amendement_rows.join("\n\n") %> <%= amendement_rows[row] %>
<% end -%>
|- |-
| colspan="2" | | colspan="2" |
Comments: Comments:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment