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,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Remote::Text::Document -- ch.oddb.org -- 27.07.2009 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'oddb/remote/object'
|
5
|
+
|
6
|
+
module ODDB
|
7
|
+
module Remote
|
8
|
+
module Text
|
9
|
+
class Document < Remote::Object
|
10
|
+
delegate :chapter_names
|
11
|
+
def empty?
|
12
|
+
@remote.empty?
|
13
|
+
end
|
14
|
+
def method_missing *args, &block
|
15
|
+
@remote.send *args, &block
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Remote::Util::M10lDocument -- ch.oddb.org -- 27.07.2009 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'oddb/remote/object'
|
5
|
+
require 'oddb/remote/text/document'
|
6
|
+
|
7
|
+
module ODDB
|
8
|
+
module Remote
|
9
|
+
module Util
|
10
|
+
class M10lDocument < Remote::Object
|
11
|
+
def descriptions
|
12
|
+
@descriptions or begin
|
13
|
+
@descriptions = @remote.descriptions.inject({}) do |memo, (key, doc)|
|
14
|
+
memo.store key.to_s, Remote::Text::Document.new(@source, doc)
|
15
|
+
memo
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Text::Chapter -- de.oddb.org -- 24.10.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'oddb/text/paragraph'
|
5
|
+
require 'oddb/text/picture'
|
6
|
+
require 'oddb/text/table'
|
7
|
+
|
8
|
+
module ODDB
|
9
|
+
module Text
|
10
|
+
class Chapter
|
11
|
+
attr_reader :name, :paragraphs
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
@paragraphs = []
|
15
|
+
end
|
16
|
+
def add_paragraph(paragraph)
|
17
|
+
@paragraphs.push paragraph unless paragraph.empty?
|
18
|
+
end
|
19
|
+
def append(chapter)
|
20
|
+
@paragraphs.concat chapter.paragraphs
|
21
|
+
end
|
22
|
+
def to_s
|
23
|
+
@paragraphs.join("\n")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Text::Document -- de.oddb.org -- 26.10.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'oddb/model'
|
5
|
+
require 'oddb/text/chapter'
|
6
|
+
|
7
|
+
module ODDB
|
8
|
+
module Text
|
9
|
+
## to migrate Document to be a subclass of Model:
|
10
|
+
# Drugs::Sequence.all { |seq| need = false; [:fachinfo, :patinfo].each { |key| if(ml = seq.instance_variable_get("@#{key}")); need = true; seq.instance_variable_set("@#{key}", nil); if(doc = ml.de); info = seq.send(key); if(prev = doc.instance_variable_get('@previous_sources')); info.previous_sources[:de] = prev; doc.instance_eval { remove_instance_variable('@previous_sources') }; end; if((source = doc.source) && (saved = Text::Document.find_by_source(source))); doc = saved; end; info.de = doc; info.save; info.de.save; end; end }; seq.save if need }
|
11
|
+
class Document < Model
|
12
|
+
attr_accessor :source, :date
|
13
|
+
attr_reader :chapters
|
14
|
+
def initialize
|
15
|
+
@chapters = []
|
16
|
+
end
|
17
|
+
def add_chapter(chapter)
|
18
|
+
@chapters.push chapter
|
19
|
+
end
|
20
|
+
def chapter(idx_or_name)
|
21
|
+
case idx_or_name
|
22
|
+
when Integer
|
23
|
+
@chapters[idx_or_name]
|
24
|
+
else
|
25
|
+
@chapters.find { |ch| ch.name == idx_or_name }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def chapter_names
|
29
|
+
@chapters.select { |chapter|
|
30
|
+
chapter.paragraphs.size > 1
|
31
|
+
}.collect { |chapter|
|
32
|
+
chapter.name
|
33
|
+
}
|
34
|
+
end
|
35
|
+
def remove_chapter(chapter)
|
36
|
+
@chapters.delete(chapter)
|
37
|
+
end
|
38
|
+
def to_s
|
39
|
+
@chapters.join("\n")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Text::Format -- de.oddb.org -- 19.10.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
module ODDB
|
5
|
+
module Text
|
6
|
+
class Format
|
7
|
+
attr_accessor :start, :end, :values
|
8
|
+
VALID_FORMATS = %w{b i sub sup u}
|
9
|
+
def initialize(*args)
|
10
|
+
@values = []
|
11
|
+
augment *args
|
12
|
+
@start = 0
|
13
|
+
@end = -1
|
14
|
+
end
|
15
|
+
def augment(*args)
|
16
|
+
@values.concat(args & VALID_FORMATS)
|
17
|
+
@values.sort!
|
18
|
+
@values.uniq!
|
19
|
+
@values
|
20
|
+
end
|
21
|
+
def range
|
22
|
+
@start..@end
|
23
|
+
end
|
24
|
+
def ==(other)
|
25
|
+
case other
|
26
|
+
when Format
|
27
|
+
@values == other.values
|
28
|
+
when Array
|
29
|
+
@values == (other & VALID_FORMATS).sort
|
30
|
+
else
|
31
|
+
false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Text::Paragraph -- de.oddb.org -- 19.10.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'delegate'
|
5
|
+
require 'fixes/ruby19'
|
6
|
+
require 'oddb/text/format'
|
7
|
+
|
8
|
+
module ODDB
|
9
|
+
module Text
|
10
|
+
class Paragraph
|
11
|
+
attr_reader :text, :formats
|
12
|
+
attr_accessor :align
|
13
|
+
def initialize(str='')
|
14
|
+
@formats = []
|
15
|
+
@text = u(str.dup)
|
16
|
+
set_format()
|
17
|
+
end
|
18
|
+
def method_missing *args, &block
|
19
|
+
@text.send *args, &block
|
20
|
+
end
|
21
|
+
def preformatted?
|
22
|
+
@preformatted
|
23
|
+
end
|
24
|
+
def set_format(*args)
|
25
|
+
if(fmt = @formats.last)
|
26
|
+
return if(fmt == args)
|
27
|
+
if(fmt.start == @text.length)
|
28
|
+
@formats.pop
|
29
|
+
fmt = @formats.last
|
30
|
+
if(fmt == args)
|
31
|
+
fmt.end = -1
|
32
|
+
return
|
33
|
+
end
|
34
|
+
else
|
35
|
+
fmt.end = (@text.length - 1)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
fmt = Text::Format.new(*args)
|
39
|
+
fmt.start = (@text.length)
|
40
|
+
@formats.push(fmt)
|
41
|
+
fmt
|
42
|
+
end
|
43
|
+
def <<(str)
|
44
|
+
if(str.is_a? Paragraph)
|
45
|
+
@align = str.align
|
46
|
+
txt = str.text
|
47
|
+
str.formats.each { |fmt|
|
48
|
+
set_format(*fmt.values)
|
49
|
+
@text << txt[fmt.range]
|
50
|
+
}
|
51
|
+
else
|
52
|
+
@text << str
|
53
|
+
end
|
54
|
+
self
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Text::Picture -- de.oddb.org -- 24.10.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'oddb/config'
|
5
|
+
require 'digest/md5'
|
6
|
+
require 'RMagick'
|
7
|
+
|
8
|
+
module ODDB
|
9
|
+
module Text
|
10
|
+
class Picture < DelegateClass(String)
|
11
|
+
attr_accessor :height, :width, :xscale, :yscale, :height_goal, :width_goal
|
12
|
+
TWIP = 20 ## see http://en.wikipedia.org/wiki/Twip
|
13
|
+
PCNT = 100
|
14
|
+
BDNS = 180 ## base density
|
15
|
+
DMAX = 360 ## maximum density
|
16
|
+
def initialize
|
17
|
+
super('')
|
18
|
+
end
|
19
|
+
def blob
|
20
|
+
[self].pack('H*')
|
21
|
+
end
|
22
|
+
def digest
|
23
|
+
@digest ||= Digest::MD5.hexdigest(self)
|
24
|
+
end
|
25
|
+
def empty?
|
26
|
+
super #|| !image
|
27
|
+
rescue StandardError => err
|
28
|
+
ODDB.logger.error("Text::Picture") {
|
29
|
+
sprintf "%s: %s", err.class, err.message
|
30
|
+
}
|
31
|
+
true
|
32
|
+
end
|
33
|
+
def finalize!
|
34
|
+
wmf = File.join ODDB.config.var, path("%s.wmf" % digest)
|
35
|
+
FileUtils.mkdir_p File.dirname(wmf)
|
36
|
+
File.open(wmf, 'w') { |fh| fh.puts blob }
|
37
|
+
|
38
|
+
twidth = @width ? @width * _xscale / PCNT : @width_goal
|
39
|
+
theight = @height ? @height * _yscale / PCNT : @height_goal
|
40
|
+
|
41
|
+
geom = sprintf("%ix%i!", twidth / TWIP, theight / TWIP)
|
42
|
+
path = File.join ODDB.config.var, path("%s.png" % digest)
|
43
|
+
|
44
|
+
# let imagemagick take care of file-conversion externally
|
45
|
+
out = %x{convert -resize #{geom} #{wmf} #{path}}
|
46
|
+
if $? != 0
|
47
|
+
raise out
|
48
|
+
end
|
49
|
+
|
50
|
+
png = File.read path
|
51
|
+
replace png.unpack('H*').first
|
52
|
+
end
|
53
|
+
def filename
|
54
|
+
@filename ||= "%s.png" % digest
|
55
|
+
end
|
56
|
+
def formats
|
57
|
+
[]
|
58
|
+
end
|
59
|
+
def image
|
60
|
+
Magick::Image.from_blob(blob).first
|
61
|
+
end
|
62
|
+
def path(fn = filename)
|
63
|
+
File.join('/images', fn[0,2], fn)
|
64
|
+
end
|
65
|
+
def set_format(*ignore)
|
66
|
+
end
|
67
|
+
def to_png
|
68
|
+
blob
|
69
|
+
end
|
70
|
+
def to_s
|
71
|
+
image.inspect
|
72
|
+
end
|
73
|
+
def _xscale
|
74
|
+
if @xscale
|
75
|
+
@xscale
|
76
|
+
elsif @width && @width_goal
|
77
|
+
PCNT * @width_goal / @width
|
78
|
+
else
|
79
|
+
PCNT
|
80
|
+
end
|
81
|
+
end
|
82
|
+
def _yscale
|
83
|
+
if @yscale
|
84
|
+
@yscale
|
85
|
+
elsif @height && @height_goal
|
86
|
+
PCNT * @height_goal / @height
|
87
|
+
else
|
88
|
+
PCNT
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Text::Table -- de.oddb.org -- 19.10.2007 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'oddb/text/paragraph'
|
5
|
+
|
6
|
+
module ODDB
|
7
|
+
module Text
|
8
|
+
class Table
|
9
|
+
attr_reader :rows
|
10
|
+
def initialize
|
11
|
+
@rows = [[]]
|
12
|
+
next_cell!
|
13
|
+
end
|
14
|
+
def clean!
|
15
|
+
@rows.each { |row|
|
16
|
+
while((cell = row.last) && cell.empty?)
|
17
|
+
row.pop
|
18
|
+
end
|
19
|
+
}
|
20
|
+
while((row = @rows.last) && row.empty?)
|
21
|
+
@rows.pop
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def column_widths
|
25
|
+
@rows.inject([]) { |memo, row|
|
26
|
+
row.each_with_index { |cell, idx|
|
27
|
+
memo[idx] = [memo[idx].to_i, cell.length].max
|
28
|
+
}
|
29
|
+
memo
|
30
|
+
}
|
31
|
+
end
|
32
|
+
def empty?
|
33
|
+
@rows.flatten.all? { |cell| cell.strip.empty? }
|
34
|
+
end
|
35
|
+
def next_cell!
|
36
|
+
cell = Paragraph.new
|
37
|
+
@rows.last.push cell
|
38
|
+
cell
|
39
|
+
end
|
40
|
+
def next_row!
|
41
|
+
@rows.push []
|
42
|
+
next_cell!
|
43
|
+
end
|
44
|
+
def each_normalized(&block)
|
45
|
+
wd = width
|
46
|
+
@rows.each { |row|
|
47
|
+
block.call(row + Array.new(wd - row.length))
|
48
|
+
}
|
49
|
+
end
|
50
|
+
def to_s
|
51
|
+
widths = column_widths
|
52
|
+
@rows.collect { |row|
|
53
|
+
line = ''
|
54
|
+
row.each_with_index { |cell, idx|
|
55
|
+
line << cell.to_s.ljust(widths.at(idx) + 2)
|
56
|
+
}
|
57
|
+
line
|
58
|
+
}.join("\n")
|
59
|
+
end
|
60
|
+
def width
|
61
|
+
@rows.collect { |row| row.length }.max
|
62
|
+
end
|
63
|
+
def <<(str)
|
64
|
+
@rows.last.last << str
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/oddb/util.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Util::AnnotatedList -- de.oddb.org -- 06.12.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
module ODDB
|
5
|
+
module Util
|
6
|
+
class AnnotatedList < Array
|
7
|
+
def initialize(annotations = {})
|
8
|
+
if(annotations.is_a?(Hash))
|
9
|
+
super()
|
10
|
+
@annotations = annotations
|
11
|
+
else
|
12
|
+
super
|
13
|
+
@annotations = {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def sort_by(*args, &block)
|
17
|
+
_delegate(super(*args, &block))
|
18
|
+
end
|
19
|
+
def [](*args, &block)
|
20
|
+
_delegate(super(*args, &block))
|
21
|
+
end
|
22
|
+
def method_missing(key, *args)
|
23
|
+
mname = key.id2name
|
24
|
+
if(args.size == 1 && /=$/.match(mname))
|
25
|
+
mname.chop!
|
26
|
+
@annotations[mname.to_sym] = args.first
|
27
|
+
else
|
28
|
+
@annotations[key]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
private
|
32
|
+
def _delegate(content)
|
33
|
+
self.dup.clear.concat(content)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Util::Code -- de.oddb.org -- 12.09.2006 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module ODDB
|
7
|
+
module Util
|
8
|
+
class Code
|
9
|
+
attr_accessor :type, :value, :country, :format
|
10
|
+
def initialize(type, value, country, valid_from=Date.today)
|
11
|
+
@values = { valid_from => value}
|
12
|
+
@type, @country = type.to_s.downcase, country.to_s.upcase
|
13
|
+
end
|
14
|
+
def hash
|
15
|
+
[@type, @value, @country].hash
|
16
|
+
end
|
17
|
+
def is_for?(type, country)
|
18
|
+
@type == type.to_s.downcase && @country == country.to_s.upcase
|
19
|
+
end
|
20
|
+
def format
|
21
|
+
@format || case @type
|
22
|
+
when 'registration'
|
23
|
+
case @country
|
24
|
+
when 'CH'
|
25
|
+
"%05i"
|
26
|
+
else
|
27
|
+
"%s"
|
28
|
+
end
|
29
|
+
else
|
30
|
+
"%s"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
def to_s
|
34
|
+
format % value
|
35
|
+
end
|
36
|
+
def value(date=Date.today)
|
37
|
+
pair = @values.sort.reverse.find { |valid_from, value|
|
38
|
+
valid_from <= date
|
39
|
+
}
|
40
|
+
pair && pair.last
|
41
|
+
end
|
42
|
+
def value=(value_and_date)
|
43
|
+
value, valid_from = nil
|
44
|
+
if(value_and_date.is_a?(Array))
|
45
|
+
value, valid_from = value_and_date
|
46
|
+
else
|
47
|
+
value = value_and_date
|
48
|
+
valid_from = Date.today
|
49
|
+
end
|
50
|
+
if(value(valid_from) != value)
|
51
|
+
@values.store(valid_from, value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
def ==(other)
|
55
|
+
if(other.is_a?(Code))
|
56
|
+
other.type == @type && other.value == value \
|
57
|
+
&& other.country == @country
|
58
|
+
elsif(other.is_a?(Hash))
|
59
|
+
res = other[:type].to_s.downcase == @type \
|
60
|
+
&& other[:value] == value \
|
61
|
+
&& other[:country] == @country
|
62
|
+
else
|
63
|
+
value == other || value.to_s == other
|
64
|
+
end
|
65
|
+
end
|
66
|
+
alias :eql? :==
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|