<< Masa.20101105-create-patinfo-ebook | 2010 | Masa.20101103-decorators-for-ebooks >>
suspend
Done
Check the calculate time to run meddrugs.ch_de_firefox
pre-process: 0'0'0 input-process: 0'1'56 decorate-process: 0'0'0 export-process: 0'2'21 post-process: 0'0'0
In total
Count the number times of calling decorate method
just_medical_de.rb
module EBPS module Decorator module JustMedical def self.decorate model @count ||= 0 p @count+=1, " " if codes = model.metadata['article_codes'] ean13s = codes.collect do |hash| hash[:article_ean13] end.compact unless ean13s.empty? chapter = Text::Chapter.new chapter.heading << 'Preisvergleich' ean13s.each do |ean13| href = "http://just-medical.oddb.org/de/just-medical/compare/ean13/#{ean13}" chapter.add_paragraph Text::LinkedParagraph.new(href, ean13) end model.add_chapter chapter end end end end end end
Run
masa@masa ~/work $ ls just_medical_de.rb meddrugs.ch_de_firefox meddrugs.ch_de_firefox.yml masa@masa ~/work $ ruby1.9 meddrugs.ch_de_firefox config="meddrugs.ch_de_firefox.yml"
Result
... 4100 4101 end decorate-process ...
Notes
Analysis
meddrugs.ch_de_firefox
.... checkTime :begin, "start decorate-process" EBPS.config.decorate.each do |path, name| require path decorator = identify_module(EBPS::Decorator, name) model.each do |doc| decorator.decorate(doc) end log.push sprintf('Decorate: %s.decorate', name) end checkTime :end, "end decorate-process" ....
Notes
Consider
Check
require 'ebps/text/chapter' module EBPS module Text class Document attr_reader :chapters, :metadata attr_accessor :title def initialize @chapters = [] @metadata = {} @title = '' end
Notes
Bingo
: Document class has 'metadata' (hash) as an access method
Check EBPS::Text::Document class structure
See
Experiment (Title modification test)
/var/ebps/bin/decorators/just_medical_de.rb
module EBPS module Decorator module JustMedical def self.decorate model if model.title =~ /Omeprazol/ p model.title model.title = "Masa" + model.title + "Hata" end ...
Run
ruby1.9 meddrugs.ch_de_firefox config="meddrugs.ch_de_firefox.yml"
Result
Experiment /var/ebps/bin/decorators/just_medical_de.rb
module EBPS module Decorator module JustMedical def self.decorate model if model.title =~ /Omeprazol/ p model.title model.title = "<a href=''>" + model.title + "</a>" end ...
Result
Check export process
/var/ebps/bin/meddrugs.ch_de_firefox
... exporter = identify_module EBPS::Conversion, export_to ... target = EBPS.config.target exporter.export model, target ...
/etc/ebps/meddrugs.ch_de_firefox.yml
... export_to: epub ...
lib/ebps/conversion/epub.rb#export
def self.export docs, target, override_tmpdir=nil Oebps.export docs, target, override_tmpdir do |tmpdir, name| compile_epub target, tmpdir, name end end
Notes
Refer
Experiment
ebps/lib/ebps/conversion/oebps.rb
class HtmlFactory < Factory def body @builder.h1 @subject.title, 'id' => @uid if @subject.title =~ /Omeprazol/ p @builder exit end ...
Run
masa@masa ~/work $ ruby1.9 -I ebps/lib meddrugs.ch_de_firefox config="meddrugs.ch_de_firefox.yml"
Result
#<Builder::XmlMarkup:0x0000001274e0e8 @indent=0, @level=2, @target="<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><title>Omeprazol - 1 A Pharma</title><link type=\"text/css\" rel=\"stylesheet\" href=\"oddb.css\"/></head><body><h1 id=\"id0720facbb3b35a26776c3ea8796f9df1\">Omeprazol - 1 A Pharma</h1>">
Experiment
ebps/lib/ebps/conversion/oebps.rb
def body # @builder.h1 @subject.title, 'id' => @uid if @subject.title =~ /Omeprazol Actavis/ @builder.h1 'id' => @uid do |xml| xml.a @subject.title, 'href' => 'http://www.ywesee.com' end else @builder.h1 @subject.title, 'id' => @uid end ....
Result
Notes
Problem
suspend
Next task ebps: link_drug_brand_name - adjust through the /etc/ebs/job_config.yml
Test
meddrugs.ch_de_firefox.yml
... link_drug_brand_name: true ...
ebps/lib/ebps/conversion/oebps.rb
module EBPS module Conversion module Oebps class Factory attr_reader :uid def initialize subject, ids, tmpdir @ids = ids @indent = EBPS.config.xml_indent @builder = Builder::XmlMarkup.new :indent => @indent @builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" @subject = subject @tmpdir = tmpdir @link_drug_brand_name = EBPS.config.link_drug_brand_name end end .... class HtmlFactory < Factory def body # @builder.h1 @subject.title, 'id' => @uid if @link_drug_brand_name search_url = ["http://just-medical.oddb.org/de/just-medical/search/zone/drugs/search_query/", @subject.title.delete('®'), "/search_type/st_sequence#best_result"].join @builder.h1 'id' => @uid do |xml| xml.a @subject.title, 'href' => search_url end else @builder.h1 @subject.title, 'id' => @uid end ....
Result
Success
Notes
masa@masa ~/work $ ruby1.9 config="meddrugs.ch_de_firefox.yml" link_drug_brand_name=true
Commit
Email IP-Address, E-shop Solution: Version 2.0
just_medical_de.rb
module EBPS module Decorator module JustMedical def self.decorate model if codes = model.metadata['article_codes'] ean13s = codes.collect do |hash| hash[:article_ean13] end.compact unless ean13s.empty? chapter = Text::Chapter.new chapter.heading << 'Preisvergleich' ean13s.each do |ean13| href = "http://just-medical.oddb.org/de/just-medical/compare/ean13/#{ean13}" #chapter.add_paragraph Text::LinkedParagraph.new(href, ean13) chapter.add_paragraph Text::LinkedParagraph.new(href, model.title + " " + ean13) end model.add_chapter chapter end end end end end end
Result
Success
and uploaded