ramaze.ch.oddb.org 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/LICENSE +339 -0
- data/Manifest.txt +285 -0
- data/README.txt +45 -0
- data/Rakefile +28 -0
- data/bin/admin +69 -0
- data/bin/exportd +63 -0
- data/bin/migrate +461 -0
- data/bin/oddbd +62 -0
- data/data/fulltext/data/dicts/french/fulltext.aff +1057 -0
- data/data/fulltext/data/dicts/french/fulltext.dict +91189 -0
- data/data/fulltext/data/dicts/french/fulltext.stop +135 -0
- data/data/fulltext/data/dicts/german/fulltext.aff +1233 -0
- data/data/fulltext/data/dicts/german/fulltext.dict +287574 -0
- data/data/fulltext/data/dicts/german/fulltext.stop +133 -0
- data/data/fulltext/data/german_compound/README +15 -0
- data/data/fulltext/data/german_compound/compound.pl +63 -0
- data/data/fulltext/data/german_compound/german.stop +20 -0
- data/data/fulltext/data/ispell-german-compound.tar.gz +0 -0
- data/data/fulltext/redist/dict_french/Makefile +12 -0
- data/data/fulltext/redist/dict_french/README.french +1 -0
- data/data/fulltext/redist/dict_french/dict_french.sql.in +7 -0
- data/data/fulltext/redist/dict_french/dict_snowball.c +56 -0
- data/data/fulltext/redist/dict_french/french_stem.c +1222 -0
- data/data/fulltext/redist/dict_french/french_stem.h +16 -0
- data/data/fulltext/redist/dict_french/subinclude.h +2 -0
- data/data/fulltext/redist/dict_german/Makefile +12 -0
- data/data/fulltext/redist/dict_german/README.german +1 -0
- data/data/fulltext/redist/dict_german/dict_german.sql.in +7 -0
- data/data/fulltext/redist/dict_german/dict_snowball.c +56 -0
- data/data/fulltext/redist/dict_german/german_stem.c +527 -0
- data/data/fulltext/redist/dict_german/german_stem.h +16 -0
- data/data/fulltext/redist/dict_german/subinclude.h +1 -0
- data/data/fulltext/redist/french_stem.c +1222 -0
- data/data/fulltext/redist/french_stem.h +16 -0
- data/data/fulltext/redist/german_stem.c +527 -0
- data/data/fulltext/redist/german_stem.h +16 -0
- data/lib/fixes/ruby19.rb +21 -0
- data/lib/fixes/selenium.rb +20 -0
- data/lib/fixes/singular.rb +8 -0
- data/lib/fixes/yaml.rb +13 -0
- data/lib/oddb.rb +11 -0
- data/lib/oddb/business/company.rb +18 -0
- data/lib/oddb/business/invoice.rb +75 -0
- data/lib/oddb/business/price.rb +60 -0
- data/lib/oddb/config.rb +73 -0
- data/lib/oddb/drugs.rb +16 -0
- data/lib/oddb/drugs/active_agent.rb +37 -0
- data/lib/oddb/drugs/atc.rb +53 -0
- data/lib/oddb/drugs/composition.rb +41 -0
- data/lib/oddb/drugs/ddd.rb +24 -0
- data/lib/oddb/drugs/dose.rb +107 -0
- data/lib/oddb/drugs/galenic_form.rb +21 -0
- data/lib/oddb/drugs/galenic_group.rb +17 -0
- data/lib/oddb/drugs/package.rb +87 -0
- data/lib/oddb/drugs/part.rb +56 -0
- data/lib/oddb/drugs/product.rb +25 -0
- data/lib/oddb/drugs/sequence.rb +61 -0
- data/lib/oddb/drugs/substance.rb +31 -0
- data/lib/oddb/drugs/substance_group.rb +13 -0
- data/lib/oddb/drugs/unit.rb +12 -0
- data/lib/oddb/export.rb +4 -0
- data/lib/oddb/export/csv.rb +89 -0
- data/lib/oddb/export/l10n_sessions.rb +30 -0
- data/lib/oddb/export/rss.rb +44 -0
- data/lib/oddb/export/server.rb +58 -0
- data/lib/oddb/export/xls.rb +119 -0
- data/lib/oddb/export/yaml.rb +123 -0
- data/lib/oddb/html/state/drugs/admin/package.rb +189 -0
- data/lib/oddb/html/state/drugs/admin/product.rb +56 -0
- data/lib/oddb/html/state/drugs/admin/sequence.rb +259 -0
- data/lib/oddb/html/state/drugs/ajax/explain_ddd_price.rb +19 -0
- data/lib/oddb/html/state/drugs/ajax/explain_price.rb +19 -0
- data/lib/oddb/html/state/drugs/ajax/global.rb +18 -0
- data/lib/oddb/html/state/drugs/ajax/package_infos.rb +19 -0
- data/lib/oddb/html/state/drugs/ajax/remote_infos.rb +19 -0
- data/lib/oddb/html/state/drugs/atc_browser.rb +39 -0
- data/lib/oddb/html/state/drugs/atc_guidelines.rb +21 -0
- data/lib/oddb/html/state/drugs/compare.rb +52 -0
- data/lib/oddb/html/state/drugs/download_export.rb +18 -0
- data/lib/oddb/html/state/drugs/fachinfo.rb +21 -0
- data/lib/oddb/html/state/drugs/feedback.rb +94 -0
- data/lib/oddb/html/state/drugs/global.rb +266 -0
- data/lib/oddb/html/state/drugs/init.rb +18 -0
- data/lib/oddb/html/state/drugs/login.rb +17 -0
- data/lib/oddb/html/state/drugs/package.rb +32 -0
- data/lib/oddb/html/state/drugs/patinfo.rb +21 -0
- data/lib/oddb/html/state/drugs/products.rb +51 -0
- data/lib/oddb/html/state/drugs/result.rb +125 -0
- data/lib/oddb/html/state/global.rb +165 -0
- data/lib/oddb/html/state/global_predefine.rb +17 -0
- data/lib/oddb/html/state/limit.rb +17 -0
- data/lib/oddb/html/state/login.rb +56 -0
- data/lib/oddb/html/state/paypal/checkout.rb +130 -0
- data/lib/oddb/html/state/paypal/collect.rb +46 -0
- data/lib/oddb/html/state/paypal/redirect.rb +18 -0
- data/lib/oddb/html/state/register_export.rb +38 -0
- data/lib/oddb/html/state/register_poweruser.rb +17 -0
- data/lib/oddb/html/state/viral/admin.rb +76 -0
- data/lib/oddb/html/state/viral/poweruser.rb +16 -0
- data/lib/oddb/html/util/annotated_list.rb +39 -0
- data/lib/oddb/html/util/know_it_all.rb +28 -0
- data/lib/oddb/html/util/known_user.rb +55 -0
- data/lib/oddb/html/util/lookandfeel.rb +554 -0
- data/lib/oddb/html/util/need_all_input.rb +29 -0
- data/lib/oddb/html/util/session.rb +88 -0
- data/lib/oddb/html/util/sort.rb +72 -0
- data/lib/oddb/html/util/unsaved_helper.rb +20 -0
- data/lib/oddb/html/util/validator.rb +54 -0
- data/lib/oddb/html/view/ajax/json.rb +22 -0
- data/lib/oddb/html/view/alpha_header.rb +28 -0
- data/lib/oddb/html/view/document.rb +126 -0
- data/lib/oddb/html/view/drugs/admin/package.rb +237 -0
- data/lib/oddb/html/view/drugs/admin/product.rb +104 -0
- data/lib/oddb/html/view/drugs/admin/sequence.rb +312 -0
- data/lib/oddb/html/view/drugs/ajax/explain_ddd_price.rb +87 -0
- data/lib/oddb/html/view/drugs/ajax/explain_price.rb +61 -0
- data/lib/oddb/html/view/drugs/ajax/package_infos.rb +105 -0
- data/lib/oddb/html/view/drugs/ajax/remote_infos.rb +44 -0
- data/lib/oddb/html/view/drugs/atc_browser.rb +68 -0
- data/lib/oddb/html/view/drugs/atc_guidelines.rb +94 -0
- data/lib/oddb/html/view/drugs/compare.rb +95 -0
- data/lib/oddb/html/view/drugs/download_export.rb +28 -0
- data/lib/oddb/html/view/drugs/fachinfo.rb +46 -0
- data/lib/oddb/html/view/drugs/feedback.rb +231 -0
- data/lib/oddb/html/view/drugs/init.rb +51 -0
- data/lib/oddb/html/view/drugs/legend.rb +24 -0
- data/lib/oddb/html/view/drugs/package.rb +398 -0
- data/lib/oddb/html/view/drugs/patinfo.rb +46 -0
- data/lib/oddb/html/view/drugs/products.rb +97 -0
- data/lib/oddb/html/view/drugs/result.rb +296 -0
- data/lib/oddb/html/view/drugs/search.rb +33 -0
- data/lib/oddb/html/view/drugs/template.rb +15 -0
- data/lib/oddb/html/view/foot.rb +52 -0
- data/lib/oddb/html/view/google.rb +23 -0
- data/lib/oddb/html/view/google_ads.rb +40 -0
- data/lib/oddb/html/view/head.rb +78 -0
- data/lib/oddb/html/view/limit.rb +109 -0
- data/lib/oddb/html/view/list.rb +59 -0
- data/lib/oddb/html/view/login.rb +38 -0
- data/lib/oddb/html/view/navigation.rb +67 -0
- data/lib/oddb/html/view/offset_header.rb +35 -0
- data/lib/oddb/html/view/paypal/collect.rb +84 -0
- data/lib/oddb/html/view/paypal/redirect.rb +51 -0
- data/lib/oddb/html/view/paypal/register_form.rb +106 -0
- data/lib/oddb/html/view/register_export.rb +29 -0
- data/lib/oddb/html/view/register_poweruser.rb +29 -0
- data/lib/oddb/html/view/rss/feedback.rb +64 -0
- data/lib/oddb/html/view/rss_preview.rb +54 -0
- data/lib/oddb/html/view/search.rb +104 -0
- data/lib/oddb/html/view/snapback.rb +24 -0
- data/lib/oddb/html/view/template.rb +56 -0
- data/lib/oddb/import/excel.rb +45 -0
- data/lib/oddb/import/import.rb +39 -0
- data/lib/oddb/import/rtf.rb +410 -0
- data/lib/oddb/import/whocc.rb +173 -0
- data/lib/oddb/import/xml.rb +15 -0
- data/lib/oddb/model.rb +179 -0
- data/lib/oddb/persistence/odba.rb +33 -0
- data/lib/oddb/persistence/odba/business/company.rb +13 -0
- data/lib/oddb/persistence/odba/business/invoice.rb +15 -0
- data/lib/oddb/persistence/odba/drugs/atc.rb +15 -0
- data/lib/oddb/persistence/odba/drugs/galenic_form.rb +18 -0
- data/lib/oddb/persistence/odba/drugs/galenic_group.rb +13 -0
- data/lib/oddb/persistence/odba/drugs/package.rb +25 -0
- data/lib/oddb/persistence/odba/drugs/product.rb +13 -0
- data/lib/oddb/persistence/odba/drugs/sequence.rb +21 -0
- data/lib/oddb/persistence/odba/drugs/substance.rb +21 -0
- data/lib/oddb/persistence/odba/drugs/substance_group.rb +13 -0
- data/lib/oddb/persistence/odba/drugs/unit.rb +13 -0
- data/lib/oddb/persistence/odba/export.rb +26 -0
- data/lib/oddb/persistence/odba/model.rb +68 -0
- data/lib/oddb/persistence/odba/regulatory/authority.rb +13 -0
- data/lib/oddb/persistence/odba/regulatory/registration.rb +13 -0
- data/lib/oddb/persistence/odba/text/document.rb +11 -0
- data/lib/oddb/persistence/odba/util/code.rb +11 -0
- data/lib/oddb/persistence/odba/util/m10l_document.rb +13 -0
- data/lib/oddb/persistence/og.rb +16 -0
- data/lib/oddb/persistence/og/drugs/composition.rb +14 -0
- data/lib/oddb/persistence/og/drugs/product.rb +14 -0
- data/lib/oddb/persistence/og/drugs/sequence.rb +15 -0
- data/lib/oddb/persistence/og/model.rb +25 -0
- data/lib/oddb/persistence/og/util/multilingual.rb +13 -0
- data/lib/oddb/redist/rtf_tools/reader.rb +139 -0
- data/lib/oddb/regulatory/authority.rb +14 -0
- data/lib/oddb/regulatory/registration.rb +15 -0
- data/lib/oddb/remote/business/company.rb +23 -0
- data/lib/oddb/remote/drugs/active_agent.rb +27 -0
- data/lib/oddb/remote/drugs/atc.rb +32 -0
- data/lib/oddb/remote/drugs/dose.rb +8 -0
- data/lib/oddb/remote/drugs/galenic_form.rb +25 -0
- data/lib/oddb/remote/drugs/package.rb +126 -0
- data/lib/oddb/remote/drugs/part.rb +30 -0
- data/lib/oddb/remote/drugs/product.rb +19 -0
- data/lib/oddb/remote/drugs/sequence.rb +46 -0
- data/lib/oddb/remote/drugs/substance.rb +20 -0
- data/lib/oddb/remote/drugs/unit.rb +19 -0
- data/lib/oddb/remote/object.rb +36 -0
- data/lib/oddb/remote/text/document.rb +20 -0
- data/lib/oddb/remote/util/m10l_document.rb +22 -0
- data/lib/oddb/text/chapter.rb +27 -0
- data/lib/oddb/text/document.rb +43 -0
- data/lib/oddb/text/format.rb +37 -0
- data/lib/oddb/text/paragraph.rb +58 -0
- data/lib/oddb/text/picture.rb +93 -0
- data/lib/oddb/text/table.rb +68 -0
- data/lib/oddb/util.rb +8 -0
- data/lib/oddb/util/annotated_list.rb +37 -0
- data/lib/oddb/util/code.rb +69 -0
- data/lib/oddb/util/comparison.rb +36 -0
- data/lib/oddb/util/exporter.rb +8 -0
- data/lib/oddb/util/feedback.rb +23 -0
- data/lib/oddb/util/ipn.rb +48 -0
- data/lib/oddb/util/m10l_document.rb +38 -0
- data/lib/oddb/util/mail.rb +73 -0
- data/lib/oddb/util/money.rb +60 -0
- data/lib/oddb/util/multilingual.rb +70 -0
- data/lib/oddb/util/quanty.rb +4 -0
- data/lib/oddb/util/quanty/fact.rb +229 -0
- data/lib/oddb/util/quanty/main.rb +160 -0
- data/lib/oddb/util/quanty/parse.rb +853 -0
- data/lib/oddb/util/quanty/units.dump +0 -0
- data/lib/oddb/util/server.rb +117 -0
- data/lib/oddb/util/updater.rb +41 -0
- data/lib/oddb/util/ydim.rb +110 -0
- data/lib/oddb/util/yus.rb +46 -0
- data/test/business/test_company.rb +29 -0
- data/test/business/test_price.rb +46 -0
- data/test/drugs/test_active_agent.rb +53 -0
- data/test/drugs/test_atc.rb +54 -0
- data/test/drugs/test_composition.rb +88 -0
- data/test/drugs/test_ddd.rb +22 -0
- data/test/drugs/test_dose.rb +190 -0
- data/test/drugs/test_galenic_form.rb +41 -0
- data/test/drugs/test_package.rb +173 -0
- data/test/drugs/test_part.rb +32 -0
- data/test/drugs/test_product.rb +31 -0
- data/test/drugs/test_sequence.rb +140 -0
- data/test/drugs/test_substance.rb +51 -0
- data/test/drugs/test_substance_group.rb +27 -0
- data/test/export/test_rss.rb +94 -0
- data/test/export/test_server.rb +117 -0
- data/test/export/test_xls.rb +152 -0
- data/test/export/test_yaml.rb +120 -0
- data/test/import/data/html/whocc/A.html +56 -0
- data/test/import/data/html/whocc/A03.html +48 -0
- data/test/import/data/html/whocc/A03AB.html +48 -0
- data/test/import/data/html/whocc/A06AA.html +47 -0
- data/test/import/data/html/whocc/C03.html +47 -0
- data/test/import/data/html/whocc/login.html +77 -0
- data/test/import/data/xml/ATC_2006.xml +47 -0
- data/test/import/data/xml/ATC_2006_ddd.xml +35 -0
- data/test/import/test_excel.rb +34 -0
- data/test/import/test_rtf.rb +40 -0
- data/test/import/test_whocc.rb +315 -0
- data/test/remote/drugs/test_active_agent.rb +36 -0
- data/test/selenium/selenium-server.jar +0 -0
- data/test/selenium/test_atc_browser.rb +122 -0
- data/test/selenium/test_atc_guidelines.rb +96 -0
- data/test/selenium/test_collect.rb +138 -0
- data/test/selenium/test_compare.rb +206 -0
- data/test/selenium/test_fachinfo.rb +130 -0
- data/test/selenium/test_feedback.rb +196 -0
- data/test/selenium/test_init.rb +52 -0
- data/test/selenium/test_limit.rb +305 -0
- data/test/selenium/test_login.rb +67 -0
- data/test/selenium/test_package.rb +512 -0
- data/test/selenium/test_patinfo.rb +131 -0
- data/test/selenium/test_product.rb +80 -0
- data/test/selenium/test_products.rb +142 -0
- data/test/selenium/test_search.rb +715 -0
- data/test/selenium/test_sequence.rb +543 -0
- data/test/selenium/unit.rb +185 -0
- data/test/stub/http_server.rb +169 -0
- data/test/stub/model.rb +173 -0
- data/test/suite.rb +15 -0
- data/test/test_model.rb +83 -0
- data/test/util/test_code.rb +74 -0
- data/test/util/test_ipn.rb +117 -0
- data/test/util/test_mail.rb +86 -0
- data/test/util/test_multilingual.rb +97 -0
- data/test/util/test_server.rb +48 -0
- data/test/util/test_updater.rb +353 -0
- data/test/util/test_ydim.rb +115 -0
- data/test/util/test_yus.rb +79 -0
- metadata +418 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Html::View::Composite -- de.oddb.org -- 14.02.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'htmlgrid/divcomposite'
|
5
|
+
|
6
|
+
module ODDB
|
7
|
+
module Html
|
8
|
+
module View
|
9
|
+
module Snapback
|
10
|
+
def snapback(model)
|
11
|
+
if(query = @session.persistent_user_input(:query))
|
12
|
+
link = HtmlGrid::Link.new(:result, model, @session, self)
|
13
|
+
link.href = @lookandfeel._event_url(:search, [ :query, query ])
|
14
|
+
link
|
15
|
+
else
|
16
|
+
link = HtmlGrid::Link.new(:home, model, @session, self)
|
17
|
+
link.href = @lookandfeel._event_url(:home)
|
18
|
+
link
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Html::View::Template -- de.oddb.org -- 27.10.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'htmlgrid/divtemplate'
|
5
|
+
require 'htmlgrid/dojotoolkit'
|
6
|
+
require 'sbsm/time'
|
7
|
+
require 'oddb/html/view/foot'
|
8
|
+
require 'oddb/html/view/head'
|
9
|
+
|
10
|
+
module ODDB
|
11
|
+
module Html
|
12
|
+
module View
|
13
|
+
class Template < HtmlGrid::DivTemplate
|
14
|
+
include HtmlGrid::DojoToolkit::DojoTemplate
|
15
|
+
FOOT = Foot
|
16
|
+
HEAD = Head
|
17
|
+
HTTP_HEADERS = {
|
18
|
+
"Content-Type" => "text/html; charset=utf-8",
|
19
|
+
"Cache-Control" => "private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0",
|
20
|
+
"Pragma" => "no-cache",
|
21
|
+
"Expires" => Time.now.rfc1123,
|
22
|
+
"P3P" => "CP='OTI NID CUR OUR STP ONL UNI PRE'",
|
23
|
+
}
|
24
|
+
COMPONENTS = {
|
25
|
+
[0,0] => :head,
|
26
|
+
[0,1] => :content,
|
27
|
+
[0,2] => NavigationFoot,
|
28
|
+
[0,3] => :foot,
|
29
|
+
}
|
30
|
+
CSS_ID_MAP = ['head', 'content', 'navigation', 'foot']
|
31
|
+
DOJO_DEBUG = ODDB.config.dojo_debug
|
32
|
+
DOJO_REQUIRE = [ 'dojo.widget.Tooltip' ]
|
33
|
+
DOJO_PARSE_WIDGETS = true
|
34
|
+
def title(context)
|
35
|
+
context.title {
|
36
|
+
_title.push(@lookandfeel.lookup(:html_owner)).join(' | ') }
|
37
|
+
end
|
38
|
+
def _title
|
39
|
+
parts = [:html_title, @session.zone]
|
40
|
+
[@session.state.direct_event].flatten.each_with_index { |part, idx|
|
41
|
+
parts << part if((idx%2) == 0)
|
42
|
+
}
|
43
|
+
parts.collect { |key|
|
44
|
+
@lookandfeel.lookup(key) { key if(key.is_a?(String)) } }.compact
|
45
|
+
end
|
46
|
+
def css_links(context)
|
47
|
+
if(@lookandfeel.enabled?(:external_css, false))
|
48
|
+
css_link(context, @lookandfeel.resource_external(:external_css))
|
49
|
+
else
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Import::Excel -- de.oddb.org -- 12.09.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'spreadsheet'
|
5
|
+
require 'oddb/import/import'
|
6
|
+
|
7
|
+
module ODDB
|
8
|
+
module Import
|
9
|
+
class Excel < Import
|
10
|
+
attr_reader :report
|
11
|
+
def cell(row, idx)
|
12
|
+
if(cell = row[idx])
|
13
|
+
case cell
|
14
|
+
when Date, DateTime
|
15
|
+
cell
|
16
|
+
when Numeric
|
17
|
+
cell.to_f
|
18
|
+
else
|
19
|
+
u(cell.to_s).strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
def import(io)
|
24
|
+
workbook = parse(io)
|
25
|
+
import_worksheet(workbook.worksheet(0))
|
26
|
+
postprocess()
|
27
|
+
report
|
28
|
+
end
|
29
|
+
def import_worksheet(worksheet)
|
30
|
+
worksheet.each(@skip_rows) { |row|
|
31
|
+
import_row(row)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
def parse(io)
|
35
|
+
Spreadsheet.open(io)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
class DatedExcel < Excel
|
39
|
+
def initialize(date = Date.today)
|
40
|
+
super()
|
41
|
+
@date = date
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Import::Import -- de.oddb.org -- 23.02.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'fixes/ruby19'
|
5
|
+
require 'iconv'
|
6
|
+
|
7
|
+
module ODDB
|
8
|
+
module Import
|
9
|
+
class Import
|
10
|
+
@@iconv = Iconv.new('utf8//IGNORE//TRANSLIT', 'latin1')
|
11
|
+
@@lower = /^(and|for|in(cl)?|on|plain|with)$/i
|
12
|
+
attr_accessor :report
|
13
|
+
def initialize
|
14
|
+
@report = []
|
15
|
+
@skip_rows = 1
|
16
|
+
end
|
17
|
+
def capitalize_all(str)
|
18
|
+
## benchmarked fastest against an append (<<) solution
|
19
|
+
str.split(/\b/).collect { |part|
|
20
|
+
@@lower.match(part) ? part.downcase : part.capitalize }.join
|
21
|
+
end
|
22
|
+
def company_name(cname)
|
23
|
+
cname = capitalize_all(cname.to_s)
|
24
|
+
cname.gsub!(/\.(?!\s)/, '. ')
|
25
|
+
cname.gsub!(/[\/&]/) { |match| ' %s ' % match }
|
26
|
+
cname.gsub!(/Gmbh/, 'GmbH')
|
27
|
+
cname.gsub!(/Ag\b/, 'AG')
|
28
|
+
cname.gsub!(/\bKg\b/, 'KG')
|
29
|
+
cname.strip!
|
30
|
+
u(cname)
|
31
|
+
end
|
32
|
+
def postprocess
|
33
|
+
end
|
34
|
+
def utf8(str)
|
35
|
+
u @@iconv.iconv(str) if str
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,410 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# Import::Rtf -- de.oddb.org -- 16.10.2007 -- hwyss@ywesee.com
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
require 'oddb/redist/rtf_tools/reader'
|
7
|
+
require 'oddb/text/chapter'
|
8
|
+
require 'oddb/text/document'
|
9
|
+
require 'oddb/text/paragraph'
|
10
|
+
require 'oddb/text/picture'
|
11
|
+
require 'oddb/text/table'
|
12
|
+
require 'RMagick'
|
13
|
+
|
14
|
+
module ODDB
|
15
|
+
module Import
|
16
|
+
class RtfReader < RTFReader
|
17
|
+
def _read_char
|
18
|
+
if @buffer.empty? && (x = @bufferstring.read(100))
|
19
|
+
@buffer = x.split(//)
|
20
|
+
end
|
21
|
+
@buffer.shift
|
22
|
+
end
|
23
|
+
end
|
24
|
+
class Rtf
|
25
|
+
SYMBOLS = {
|
26
|
+
0101 => "Α",
|
27
|
+
0102 => "Β",
|
28
|
+
0103 => "Χ",
|
29
|
+
0104 => "Δ",
|
30
|
+
0105 => "Ε",
|
31
|
+
0110 => "Η",
|
32
|
+
0240 => "€",
|
33
|
+
0107 => "Γ",
|
34
|
+
0301 => "ℑ",
|
35
|
+
0111 => "Ι",
|
36
|
+
0113 => "Κ",
|
37
|
+
0114 => "Λ",
|
38
|
+
0115 => "Μ",
|
39
|
+
0116 => "Ν",
|
40
|
+
0127 => "Ω",
|
41
|
+
0117 => "Ο",
|
42
|
+
0106 => "Φ",
|
43
|
+
0120 => "Π",
|
44
|
+
0131 => "Ψ",
|
45
|
+
0302 => "ℜ",
|
46
|
+
0122 => "Ρ",
|
47
|
+
0123 => "Σ",
|
48
|
+
0124 => "Τ",
|
49
|
+
0121 => "Θ",
|
50
|
+
0125 => "Υ",
|
51
|
+
0241 => "ϒ",
|
52
|
+
0130 => "Ξ",
|
53
|
+
0132 => "Ζ",
|
54
|
+
0300 => "ℵ",
|
55
|
+
0141 => "α",
|
56
|
+
0046 => "&",
|
57
|
+
0320 => "∠",
|
58
|
+
0341 => "〈",
|
59
|
+
0361 => "〉",
|
60
|
+
0273 => "≈",
|
61
|
+
0253 => "↔",
|
62
|
+
0333 => "⇔",
|
63
|
+
0337 => "⇓",
|
64
|
+
0334 => "⇐",
|
65
|
+
0336 => "⇒",
|
66
|
+
0335 => "⇑",
|
67
|
+
0257 => "↓",
|
68
|
+
0276 => "",
|
69
|
+
0254 => "←",
|
70
|
+
0256 => "→",
|
71
|
+
0255 => "↑",
|
72
|
+
0275 => "",
|
73
|
+
0052 => "∗",
|
74
|
+
0174 => "|",
|
75
|
+
0142 => "β",
|
76
|
+
0173 => "{",
|
77
|
+
0175 => "}",
|
78
|
+
0354 => "",
|
79
|
+
0355 => "",
|
80
|
+
0356 => "",
|
81
|
+
0374 => "",
|
82
|
+
0375 => "",
|
83
|
+
0376 => "",
|
84
|
+
0357 => "",
|
85
|
+
0133 => "[",
|
86
|
+
0135 => "]",
|
87
|
+
0351 => "",
|
88
|
+
0352 => "",
|
89
|
+
0353 => "",
|
90
|
+
0371 => "",
|
91
|
+
0372 => "",
|
92
|
+
0373 => "",
|
93
|
+
0267 => "•",
|
94
|
+
0277 => "↵",
|
95
|
+
0143 => "χ",
|
96
|
+
0304 => "⊗",
|
97
|
+
0305 => "⊕",
|
98
|
+
0247 => "♣",
|
99
|
+
0072 => ":",
|
100
|
+
0054 => ",",
|
101
|
+
0100 => "≅",
|
102
|
+
0343 => "",
|
103
|
+
0260 => "°",
|
104
|
+
0144 => "δ",
|
105
|
+
0250 => "♦",
|
106
|
+
0270 => "÷",
|
107
|
+
0327 => "⋅",
|
108
|
+
0070 => "8",
|
109
|
+
0316 => "∈",
|
110
|
+
0274 => "…",
|
111
|
+
0306 => "∅",
|
112
|
+
0145 => "ε",
|
113
|
+
0075 => "=",
|
114
|
+
0272 => "≡",
|
115
|
+
0150 => "η",
|
116
|
+
0041 => "!",
|
117
|
+
0044 => "∃",
|
118
|
+
0065 => "5",
|
119
|
+
0246 => "ƒ",
|
120
|
+
0064 => "4",
|
121
|
+
0244 => "⁄",
|
122
|
+
0147 => "γ",
|
123
|
+
0321 => "∇",
|
124
|
+
0076 => ">",
|
125
|
+
0263 => "≥",
|
126
|
+
0251 => "♥",
|
127
|
+
0245 => "∞",
|
128
|
+
0362 => "∫",
|
129
|
+
0363 => "⌠",
|
130
|
+
0364 => "",
|
131
|
+
0365 => "⌡",
|
132
|
+
0307 => "∩",
|
133
|
+
0151 => "ι",
|
134
|
+
0153 => "κ",
|
135
|
+
0154 => "λ",
|
136
|
+
0074 => "<",
|
137
|
+
0243 => "≤",
|
138
|
+
0331 => "∧",
|
139
|
+
0330 => "¬",
|
140
|
+
0332 => "∨",
|
141
|
+
0340 => "◊",
|
142
|
+
0055 => "−",
|
143
|
+
0242 => "′",
|
144
|
+
0155 => "μ",
|
145
|
+
0264 => "×",
|
146
|
+
0071 => "9",
|
147
|
+
0317 => "∉",
|
148
|
+
0271 => "≠",
|
149
|
+
0313 => "⊄",
|
150
|
+
0156 => "ν",
|
151
|
+
0043 => "#",
|
152
|
+
0167 => "ω",
|
153
|
+
0166 => "ϖ",
|
154
|
+
0157 => "ο",
|
155
|
+
0061 => "1",
|
156
|
+
0050 => "(",
|
157
|
+
0051 => ")",
|
158
|
+
0346 => "",
|
159
|
+
0347 => "",
|
160
|
+
0350 => "",
|
161
|
+
0366 => "",
|
162
|
+
0367 => "",
|
163
|
+
0370 => "",
|
164
|
+
0266 => "∂",
|
165
|
+
0045 => "%",
|
166
|
+
0056 => ".",
|
167
|
+
0136 => "⊥",
|
168
|
+
0146 => "φ",
|
169
|
+
0160 => "π",
|
170
|
+
0053 => "+",
|
171
|
+
0261 => "±",
|
172
|
+
0325 => "Π",
|
173
|
+
0314 => "⊂",
|
174
|
+
0311 => "⊃",
|
175
|
+
0265 => "∝",
|
176
|
+
0171 => "ψ",
|
177
|
+
0077 => "?",
|
178
|
+
0326 => "√",
|
179
|
+
0315 => "⊆",
|
180
|
+
0312 => "⊇",
|
181
|
+
0342 => "",
|
182
|
+
0162 => "ρ",
|
183
|
+
0262 => "″",
|
184
|
+
0073 => ";",
|
185
|
+
0067 => "7",
|
186
|
+
0163 => "σ",
|
187
|
+
0126 => "ς",
|
188
|
+
0176 => "∼",
|
189
|
+
0066 => "6",
|
190
|
+
0057 => "/",
|
191
|
+
0252 => "♠",
|
192
|
+
0047 => "∋",
|
193
|
+
0345 => "Σ",
|
194
|
+
0164 => "τ",
|
195
|
+
0134 => "∴",
|
196
|
+
0161 => "θ",
|
197
|
+
0063 => "3",
|
198
|
+
0344 => "",
|
199
|
+
0062 => "2",
|
200
|
+
0137 => "_",
|
201
|
+
0310 => "∪",
|
202
|
+
0042 => "∀",
|
203
|
+
0165 => "υ",
|
204
|
+
0303 => "℘",
|
205
|
+
0170 => "ξ",
|
206
|
+
0060 => "0",
|
207
|
+
0172 => "ζ",
|
208
|
+
}
|
209
|
+
def import(io)
|
210
|
+
reader = RtfReader.new(io)
|
211
|
+
@codepage = 'cp1252'
|
212
|
+
@groups = [[]]
|
213
|
+
init
|
214
|
+
begin
|
215
|
+
type = import_token(reader)
|
216
|
+
end until type == 'eof'
|
217
|
+
@document
|
218
|
+
end
|
219
|
+
def align(align)
|
220
|
+
current_group.push align
|
221
|
+
@buffer.align = align
|
222
|
+
end
|
223
|
+
def current_chapter
|
224
|
+
@document.chapters.last
|
225
|
+
end
|
226
|
+
def current_group
|
227
|
+
@groups.last
|
228
|
+
end
|
229
|
+
def current_table
|
230
|
+
@table ||= Text::Table.new
|
231
|
+
end
|
232
|
+
def identify_chapter buffer
|
233
|
+
current_chapter
|
234
|
+
end
|
235
|
+
def ignore?
|
236
|
+
!(current_group & [:ignore, 'v']).empty?
|
237
|
+
end
|
238
|
+
def import_control(value, extra)
|
239
|
+
case value
|
240
|
+
when '\\ansicpg'
|
241
|
+
@codepage = "cp#{extra}"
|
242
|
+
when '\\fonttbl', '\\colortbl', '\\stylesheet', '\\listtable',
|
243
|
+
'\\listoverridetable', '\\rsidtbl', '\\generator', '\\info',
|
244
|
+
'\header', '\\headerr', '\footer', '\\footerf', '\\footerr',
|
245
|
+
'\\deleted'
|
246
|
+
current_group.push :ignore
|
247
|
+
when '\\b', '\\i', '\\sub', '\\v'
|
248
|
+
if(extra == '0')
|
249
|
+
current_group.delete(value[1..-1])
|
250
|
+
else
|
251
|
+
current_group.push(value[1..-1]).uniq!
|
252
|
+
end
|
253
|
+
when '\\cell'
|
254
|
+
current_table << @buffer
|
255
|
+
@buffer = next_paragraph
|
256
|
+
@table.next_cell!
|
257
|
+
when '\\dn'
|
258
|
+
current_group.push "sub"
|
259
|
+
when '\\endash', '\\emdash'
|
260
|
+
@buffer << '-'
|
261
|
+
when '\\fs'
|
262
|
+
set_font_size(extra)
|
263
|
+
when '\\intbl'
|
264
|
+
@table_flag = true
|
265
|
+
when '\\line'
|
266
|
+
@buffer << "\n" unless @buffer.empty?
|
267
|
+
when '\\par'
|
268
|
+
if @table_flag
|
269
|
+
# do nothing
|
270
|
+
elsif @table
|
271
|
+
@table.clean!
|
272
|
+
unless @table.empty?
|
273
|
+
current_chapter.add_paragraph @table
|
274
|
+
end
|
275
|
+
@table = nil
|
276
|
+
else
|
277
|
+
unless ignore? || @buffer.empty?
|
278
|
+
chapter = identify_chapter @buffer
|
279
|
+
chapter.add_paragraph @buffer
|
280
|
+
@buffer = next_paragraph
|
281
|
+
end
|
282
|
+
end
|
283
|
+
when '\\pict'
|
284
|
+
current_group.push :picture
|
285
|
+
@buffer = Text::Picture.new
|
286
|
+
when '\\pich'
|
287
|
+
@buffer.height = extra.to_i
|
288
|
+
when '\\pichgoal'
|
289
|
+
@buffer.height_goal = extra.to_i
|
290
|
+
when '\\picw'
|
291
|
+
@buffer.width = extra.to_i
|
292
|
+
when '\\picwgoal'
|
293
|
+
@buffer.width_goal = extra.to_i
|
294
|
+
when '\\picscalex'
|
295
|
+
@buffer.xscale = extra.to_i
|
296
|
+
when '\\picscaley'
|
297
|
+
@buffer.yscale = extra.to_i
|
298
|
+
when '\\plain'
|
299
|
+
current_group.delete_if { |item| item.is_a? String }
|
300
|
+
when '\\qc'
|
301
|
+
align :center
|
302
|
+
when '\\qj'
|
303
|
+
align :justify
|
304
|
+
when '\\ql'
|
305
|
+
align :left
|
306
|
+
when '\\qr'
|
307
|
+
align :right
|
308
|
+
when '\\row'
|
309
|
+
current_table.next_row!
|
310
|
+
@table_flag = nil
|
311
|
+
when '\\super'
|
312
|
+
current_group.push 'sup'
|
313
|
+
when '\\tab'
|
314
|
+
_import_text("\t")
|
315
|
+
when '\\ul'
|
316
|
+
current_group.push "u"
|
317
|
+
when '\\up'
|
318
|
+
current_group.push "super"
|
319
|
+
when '\\wmetafile'
|
320
|
+
current_group.push "wmf"
|
321
|
+
end
|
322
|
+
end
|
323
|
+
def import_group(value, extra)
|
324
|
+
case value
|
325
|
+
when '{'
|
326
|
+
@groups.push current_group.dup
|
327
|
+
when '}'
|
328
|
+
@groups.pop
|
329
|
+
if(@buffer.is_a?(Text::Picture) && !current_group.include?(:picture))
|
330
|
+
@buffer = next_paragraph
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
def import_text(value, extra)
|
335
|
+
case value
|
336
|
+
when '\\*'
|
337
|
+
current_group.push :ignore
|
338
|
+
when /SYMBOL\s*\d/i
|
339
|
+
_import_text SYMBOLS[value[/\d+/].to_i].to_s
|
340
|
+
else
|
341
|
+
value.gsub!(/\r\n/, '')
|
342
|
+
value.gsub!(/\\'([0-9a-f]{2})/i) { |match|
|
343
|
+
match[2,2].to_i(16).chr
|
344
|
+
}
|
345
|
+
begin
|
346
|
+
value.force_encoding @codepage
|
347
|
+
value = value.encode('utf-8')
|
348
|
+
rescue
|
349
|
+
end
|
350
|
+
_import_text(value) unless ignore?
|
351
|
+
end
|
352
|
+
end
|
353
|
+
def _import_text(value)
|
354
|
+
@buffer.set_format(*current_group)
|
355
|
+
_sanitize_text(value)
|
356
|
+
value.gsub!(/\\-/, '')
|
357
|
+
value.gsub!(/\\~/, ' ')
|
358
|
+
value.gsub!(/\\_/, '-')
|
359
|
+
@buffer << value
|
360
|
+
end
|
361
|
+
def import_token(reader)
|
362
|
+
type, value, extra = reader.get_token
|
363
|
+
case type
|
364
|
+
when 'control'
|
365
|
+
if(value == '\\rtf')
|
366
|
+
@valid = true
|
367
|
+
end
|
368
|
+
import_control(value, extra)
|
369
|
+
when 'group'
|
370
|
+
import_group(value, extra)
|
371
|
+
when 'text'
|
372
|
+
unless @valid
|
373
|
+
raise ArgumentError, "Invalid RTF-File: Text before rtf-version"
|
374
|
+
end
|
375
|
+
import_text(value, extra)
|
376
|
+
end
|
377
|
+
type
|
378
|
+
end
|
379
|
+
def init
|
380
|
+
@buffer = next_paragraph
|
381
|
+
@document = Text::Document.new
|
382
|
+
@document.add_chapter Text::Chapter.new('default')
|
383
|
+
end
|
384
|
+
def next_paragraph
|
385
|
+
_next_paragraph
|
386
|
+
par = Text::Paragraph.new
|
387
|
+
par.align = (current_group & [:left, :right, :center, :justify]).last
|
388
|
+
par
|
389
|
+
end
|
390
|
+
def _next_paragraph
|
391
|
+
case @buffer
|
392
|
+
when Text::Picture
|
393
|
+
unless ignore? || @buffer.empty?
|
394
|
+
@buffer.finalize!
|
395
|
+
current_chapter.add_paragraph @buffer
|
396
|
+
end
|
397
|
+
end
|
398
|
+
rescue StandardError => error
|
399
|
+
ODDB.logger.error("RTF") { sprintf "%s: %s", error.class, error.message }
|
400
|
+
end
|
401
|
+
def parent_group
|
402
|
+
@groups[-2] || []
|
403
|
+
end
|
404
|
+
def set_font_size(size)
|
405
|
+
end
|
406
|
+
def _sanitize_text(value)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|