Class: Brand2csv::Swissreg::Vereinfachte

Inherits:
Object
  • Object
show all
Defined in:
lib/brand2csv.rb

Constant Summary collapse

HitRegexpDE =
/Seite (\d*) von ([\d']*) - Treffer ([\d']*)-([\d']*) von ([\d']*)/
Vivian =
'id_swissreg:mainContent:vivian'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Vereinfachte

Parse a HTML page from swissreg sr3.jsp There we find info like “Seite 1 von 26 - Treffer 1-250 von 6’349” and upto 250 links to details



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/brand2csv.rb', line 434

def initialize(doc)
  @inputData = []
  @pageNr = @nrSubPages = @firstHit = @nrHits = 0
  m = HitRegexpDE.match(doc.text)
  if m
    begin
      c = m.to_a.map{|n| n.gsub(/'/, "").to_i }
      @pageNr     = c[1]
      @nrSubPages = c[2]
      @firstHit   = c[3]
      @nrHits     = c[5]
    rescue NoMethodError
    end
  end
  @trademark_search_id = Swissreg::inputValue(Swissreg::getInputValuesFromPage(doc), Vivian)
  @links2details = []
  doc.search('input').each{ |input| 
                          # puts "name: #{input.attribute('name')} value #{input.attribute('value')}" if $VERBOSE
                          @inputData << [ input.attribute('name').to_s, input.attribute('value').to_s ]
                          }
  
  @state = Swissreg::inputValue(Swissreg::getInputValuesFromPage(doc),  'javax.faces.ViewState')
  doc.search('a').each{ 
    |link| 
      if m = DetailRegexp.match(link.attribute('id'))
        # puts "XXX #{link.attribute('onclick').to_s} href: #{link.attribute('href').to_s} value #{link.attribute('value').to_s}" if $VERBOSE
        m  = /'tmMainId','(\d*)'/.match(link.attribute('onclick').to_s)
        tmMainId = m[1].to_i
        @links2details << tmMainId
      end      
  }      
end

Instance Attribute Details

#firstHitObject (readonly)

Returns the value of attribute firstHit.



428
429
430
# File 'lib/brand2csv.rb', line 428

def firstHit
  @firstHit
end

#inputDataObject (readonly)

Returns the value of attribute inputData.



428
429
430
# File 'lib/brand2csv.rb', line 428

def inputData
  @inputData
end

#links2detailsObject (readonly)

Returns the value of attribute links2details.



428
429
430
# File 'lib/brand2csv.rb', line 428

def links2details
  @links2details
end

#nrHitsObject (readonly)

Returns the value of attribute nrHits.



428
429
430
# File 'lib/brand2csv.rb', line 428

def nrHits
  @nrHits
end

#nrSubPagesObject (readonly)

Returns the value of attribute nrSubPages.



428
429
430
# File 'lib/brand2csv.rb', line 428

def nrSubPages
  @nrSubPages
end

#pageNrObject (readonly)

Returns the value of attribute pageNr.



428
429
430
# File 'lib/brand2csv.rb', line 428

def pageNr
  @pageNr
end

#trademark_search_idObject (readonly)

Returns the value of attribute trademark_search_id.



428
429
430
# File 'lib/brand2csv.rb', line 428

def trademark_search_id
  @trademark_search_id
end

Instance Method Details

#getPostDataForDetail(position, id) ⇒ Object



467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/brand2csv.rb', line 467

def getPostDataForDetail(position, id)
  [
    [ "autoScroll", "0,0"],
    [ "id_swissreg:mainContent:sub_options_result:sub_fieldset:cbxHitsPerPage", "#{HitsPerPage}"],
    [ "id_swissreg:mainContent:vivian", @trademark_search_id],
    [ "id_swissreg_SUBMIT", "1"],
    [ "id_swissreg:_idcl", "id_swissreg:mainContent:data:#{position}:tm_no_detail:id_detail", ""],
    [ "id_swissreg:mainContent:scroll_1", ""],
    [ "tmMainId", "#{id}"],
    [ "id_swissreg:_link_hidden_ "],
    [ "javax.faces.ViewState", @state]
  ]
end

#getPostDataForSubpage(pageNr) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/brand2csv.rb', line 481

def getPostDataForSubpage(pageNr)
  [
    [ "autoScroll", "0,0"],
    [ "id_swissreg:mainContent:sub_options_result:sub_fieldset:cbxHitsPerPage", "#{HitsPerPage}"],
    [ "id_swissreg:mainContent:vivian", @trademark_search_id],
    [ "id_swissreg_SUBMIT", "1"],
    [ "id_swissreg:_idcl", "id_swissreg:mainContent:scroll_1idx#{pageNr}"],
    [ "id_swissreg:mainContent:scroll_1", "idx#{pageNr}"],
    [ "tmMainId", ""],
    [ "id_swissreg:_link_hidden_ "],
    [ "javax.faces.ViewState", @state]
  ]
end