Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LQDN Adminsys
amendments
Commits
1dc02c07
Commit
1dc02c07
authored
Apr 04, 2011
by
Michael Witrant
Browse files
finition extraction
parent
8e2fbe9d
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
convert
View file @
1dc02c07
...
...
@@ -19,72 +19,54 @@ require 'rubygems'
require
'pp'
require
'nokogiri'
require
'unindent'
require
'erb'
sections
=
data
.
scan
(
%r(<Amend>.+?</Amend>)m
)
sections
.
each
do
|
xml
|
doc
=
Nokogiri
::
XML
(
xml
)
num
,
note
=
doc
.
css
(
'NumAm'
).
text
.
split
(
' '
,
2
)
note
.
gsub!
(
/\s/
,
''
)
if
note
color
=
case
note
.
to_s
.
gsub
(
/[^-+]/
,
''
)
when
"--"
"green"
when
"-"
"lightgreen"
when
"++"
"red"
when
"+"
"IndianRed"
when
""
"lightgrey"
else
raise
"Invalid note:
#{
note
.
inspect
}
"
end
infos
=
xml
.
scan
(
%r(Text proposed by the Commission
\n
Amendment
\n
(.+)
\n
Or.)m
).
first
raise
"No info found"
unless
infos
infos
=
infos
.
first
.
split
(
/\n/
)
template
=
ERB
.
new
File
.
read
(
'template.erb'
),
nil
,
'-'
commission_rows
=
[]
amendement_rows
=
[]
infos
.
each_slice
(
2
)
do
|
commission
,
amendement
|
commission_rows
<<
commission
amendement_rows
<<
amendement
end
commission_rows
,
amendement_rows
=
[
commission_rows
,
amendement_rows
].
map
do
|
rows
|
rows
.
delete_if
{
|
row
|
row
.
nil?
or
row
.
empty?
}
rows
.
join
(
"
\n
"
)
end
members
=
doc
.
css
(
'Members'
).
text
article
=
doc
.
css
(
'Article'
).
text
puts
<<-
TEXT
.
unindent
== Amendement
#{
num
}
==
{| border="1" style="border-spacing:0;" cellpadding="3"
|-
! colspan="2" style="background-color:
#{
color
}
;" |
Amendement
#{
num
}
<br/>
#{
article
}
<br/>
#{
members
}
<br/>
#{
note
}
|-
|
#{
commission_rows
}
||
#{
amendement_rows
}
|-
| colspan="2" |
<!-- Commentaires -->
|}
File
.
open
"result.txt"
,
"w"
do
|
f
|
sections
.
each
do
|
xml
|
doc
=
Nokogiri
::
XML
(
xml
)
TEXT
end
num
,
note
=
doc
.
css
(
'NumAm'
).
text
.
split
(
' '
,
2
)
note
.
gsub!
(
/\s/
,
''
)
if
note
color
=
case
note
.
to_s
.
gsub
(
/[^-+]/
,
''
)
when
"--"
"green"
when
"-"
"lightgreen"
when
"++"
"red"
when
"+"
"IndianRed"
when
""
"lightgrey"
else
raise
"Invalid note:
#{
note
.
inspect
}
"
end
infos
=
xml
.
scan
(
%r(Text proposed by the Commission
\n
Amendment
\n
(.+)
\n
Or.)m
).
first
raise
"No info found"
unless
infos
infos
=
infos
.
first
.
split
(
/\n/
)
commission_rows
=
[]
amendement_rows
=
[]
infos
.
each_slice
(
2
)
do
|
commission
,
amendement
|
commission_rows
<<
commission
amendement_rows
<<
amendement
end
[
commission_rows
,
amendement_rows
].
each
do
|
rows
|
rows
.
delete_if
{
|
row
|
row
.
nil?
or
row
.
empty?
}
end
members
=
doc
.
css
(
'Members'
).
text
article
=
doc
.
css
(
'Article'
).
text
f
.
puts
template
.
result
(
binding
)
end
end
result.txt
0 → 100644
View file @
1dc02c07
This diff is collapsed.
Click to expand it.
template.erb
0 → 100644
View file @
1dc02c07
== Amendement
<%=
num
%>
==
{| border="1" style="border-spacing:0;" cellpadding="3"
|-
! colspan="2" style="background-color:
<%=
color
%>
;" |
Amendement
<%=
num
%>
<br/>
<%=
article
%>
<br/>
<%=
members
%>
<br/>
<%=
note
%>
|-
|width="50%"|
<%=
commission_rows
.
join
(
"
\n\n
"
)
%>
|width="50%"|
<%=
amendement_rows
.
join
(
"
\n\n
"
)
%>
|-
| colspan="2" |
<!-- Commentaires -->
|}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment