<< | Index | >>

git status
# Changed but not updated: # modified: ext/swissindex/src/swissindex.rb # modified: src/state/global.rb # modified: src/util/validator.rb # modified: src/view/migel/result.rb # Untracked files: # src/state/migel/test.rb # src/view/migel/test.rb
Next
Experiment
#!/usr/bin/env ruby
# ODDB::State::Migel:Test -- oddb.org -- 09.08.2011 -- mhatakeyama@ywesee.com
require 'state/global_predefine'
require 'view/migel/test'
module ODDB
module State
module Migel
class TestModel
def masa
'masamasa'
end
end
class Test < State::Migel::Global
VIEW = View::Migel::Test
def init
@model = [TestModel.new]
end
end
end
end
end
#!/usr/bin/env ruby
# ODDB::View::Migel::Test -- oddb.org -- 09.08.2011 -- mhatakeyama@ywesee.com
require 'htmlgrid/list'
module ODDB
module View
module Migel
class List < HtmlGrid::List
def init
@components = {
[0,0] => :masa,
[1,0] => 'hata',
}
super
end
def compose_list(model=@model, offset=[0,0])
super(model, offset)
end
end
class ResultComposite < HtmlGrid::Composite
COMPONENTS = {
[0,0] => List
}
end
class Test < View::PrivateTemplate
CONTENT = ResultComposite
end
end
end
end
Access
Result

Note
Next
Experiment
def search_migel_table(code, query_key = 'Pharmacode')
agent = Mechanize.new
try_time = 3
begin
agent.get(@base_url + query_key + '=' + code)
count = 100
table = []
line = []
agent.page.search('td').each_with_index do |td, i|
text = td.inner_text.chomp.strip
if text.is_a?(String) && text.length == 7 && text.match(/\d{7}/)
unless table
table = []
else
table << line
line = []
end
count = 0
end
if count < 7
text = text.split(/\n/)[1] || text.split(/\n/)[0]
text = text.gsub(/\302\240/, '').strip if text
line << text
count += 1
end
end
table << line
table.shift
table
rescue StandardError, Timeout::Error => err
if try_time > 0
puts err
puts err.backtrace
puts
puts "retry"
sleep 10
agent = Mechanize.new
try_time -= 1
retry
else
return []
end
end
end
def search_migel_table(migel_code)
table = nil
open('/home/masa/work/log.dat', 'w') do |out|
SWISSINDEX_NONPHARMA_SERVER.session(ODDB::Swissindex::SwissindexNonpharma) do |swissindex|
table = swissindex.search_migel_table(migel_code, 'MiGelCode')
end
out.print table.pretty_inspect
end
table.length.to_s + ' lines'
end
Run
ch.oddb> ODDB::SwissindexNonpharmaPlugin.new(self).search_migel_table '50704001' -> 157 lines
Result
[["4674132", "3M FUTURO Daumenschiene L/XL", "3M Consumer Health Care", "", "52.60", "1", "52.60"], ...
Next
Experiment
STRINGS = [
...
:migel_code
]
class MigelSearchedData
def initialize(session, migel_code)
plugin = ODDB::SwissindexNonpharmaPlugin.new(session.app)
@table = plugin.search_migel_table(migel_code)
@line = -1
end
def empty?
nil
end
def each_with_index
@table.each do |line|
yield self
end
end
def masa
@table[@line+=1][0]
end
end
def test
migel_code = @session.user_input(:migel_code)
ODDB::State::Migel::Test.new(@session, MigelSearchedData.new(@session, migel_code))
end
Access
Result

Note
Experiment
DICTIONARIES = {
'de' => {
...
:th_article_name => 'Artikelname',
:th_companyname => 'Companyname',
:th_ppha => 'PPHA',
:th_ppub => 'PPUB',
:th_factor => 'Faktor',
:th_pzr => 'PZR'
class MigelSearchedData
def initialize(session, migel_code)
plugin = ODDB::SwissindexNonpharmaPlugin.new(session.app)
@table = plugin.search_migel_table(migel_code)
@line = -1
end
def empty?
nil
end
def each_with_index
@table.each do |line|
yield self
end
end
def pharmacode
@table[@line+=1][0]
end
def article_name
@table[@line][1]
end
def companyname
@table[@line][2]
end
def ppha
@table[@line][3]
end
def ppub
@table[@line][4]
end
def factor
@table[@line][5]
end
def pzr
@table[@line][6]
end
end
def test
migel_code = @session.user_input(:migel_code)
ODDB::State::Migel::Test.new(@session, MigelSearchedData.new(@session, migel_code))
end
#!/usr/bin/env ruby
# ODDB::State::Migel:Test -- oddb.org -- 09.08.2011 -- mhatakeyama@ywesee.com
require 'state/global_predefine'
require 'view/migel/test'
module ODDB
module State
module Migel
class Test < State::Migel::Global
VIEW = View::Migel::Test
end
end
end
end
#!/usr/bin/env ruby
# ODDB::View::Migel::Test -- oddb.org -- 08.08.2011 -- mhatakeyama@ywesee.com
require 'htmlgrid/list'
module ODDB
module View
module Migel
class List < HtmlGrid::List
def init
@components = {
[0,0] => :pharmacode,
[1,0] => :article_name,
[2,0] => :companyname,
[3,0] => :ppha,
[4,0] => :ppub,
[5,0] => :factor,
[6,0] => :pzr,
}
super
end
def compose_list(model=@model, offset=[0,0])
super(model, offset)
end
end
class ResultComposite < HtmlGrid::Composite
COMPONENTS = {
[0,0] => List
}
end
class Test < View::PrivateTemplate
CONTENT = ResultComposite
end
end
end
end
def search_migel_table(migel_code)
table = nil
SWISSINDEX_NONPHARMA_SERVER.session(ODDB::Swissindex::SwissindexNonpharma) do |swissindex|
table = swissindex.search_migel_table(migel_code, 'MiGelCode')
end
table
end
def search_migel_table(code, query_key = 'Pharmacode')
# 'MiGelCode' is also available for query_key
agent = Mechanize.new
try_time = 3
begin
agent.get(@base_url + query_key + '=' + code)
count = 100
table = []
line = []
agent.page.search('td').each_with_index do |td, i|
text = td.inner_text.chomp.strip
if text.is_a?(String) && text.length == 7 && text.match(/\d{7}/)
unless table
table = []
else
table << line
line = []
end
count = 0
end
if count < 7
text = text.split(/\n/)[1] || text.split(/\n/)[0]
text = text.gsub(/\302\240/, '').strip if text
line << text
count += 1
end
end
table << line
table.shift
table
rescue StandardError, Timeout::Error => err
if try_time > 0
puts err
puts err.backtrace
puts
puts "retry"
sleep 10
agent = Mechanize.new
try_time -= 1
retry
else
return []
end
end
end
EVENTS = [
...
:test
...
STRINGS = [
...
:migel_code
...
Run
Access
Result

Next
Experiment
#!/usr/bin/env ruby
# encoding: utf-8
# ODDB::Migel::SearchedTable -- oddb.org -- 09.08.2011 -- mhatakeyama@ywesee.com
require 'plugin/swissindex'
module ODDB
module Migel
class SearchedTable
class Record
attr_reader :pharmacode, :article_name, :companyname, :ppha, :ppub, :factor, :pzr
def initialize(record)
@pharmacode, @article_name, @companyname, @ppha, @ppub, @factor, @pzr = *record
end
end
def initialize(session, migel_code)
plugin = ODDB::SwissindexNonpharmaPlugin.new(session.app)
@table = plugin.search_migel_table(migel_code).map do |record|
Record.new(record)
end
end
def empty?
@table.empty?
end
def sort_by
@table.sort_by do |record|
yield record
end
end
def each_with_index
@table.each do |record|
yield record
end
end
end
end
end
Access
Result
Next
Final today
