Class: Relaton::Cen::HitCollection
- Inherits:
-
Relaton::Core::HitCollection
- Object
- Relaton::Core::HitCollection
- Relaton::Cen::HitCollection
- Defined in:
- lib/relaton/cen/hit_collection.rb
Overview
Page of hit collection.
Constant Summary collapse
- DOMAIN =
"https://standards.cencenelec.eu"
Instance Method Summary collapse
- #agent ⇒ Object
-
#search ⇒ Object
def initialize(ref, year = nil) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity super ref, year.
- #select!(&block) ⇒ Object
Instance Method Details
#agent ⇒ Object
30 31 32 |
# File 'lib/relaton/cen/hit_collection.rb', line 30 def agent @agent ||= Mechanize.new.tap { |a| a.user_agent_alias = "Mac Safari" } end |
#search ⇒ Object
def initialize(ref, year = nil) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
super ref, year
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/relaton/cen/hit_collection.rb', line 13 def search if !ref || ref.empty? @array = [] return self end redirect_page = agent.get DOMAIN redirect_url = redirect_page.body.slice(/(?<=follow the <a href=')#{DOMAIN}[^']+/) search_page = agent.get redirect_url form = search_page.form_with(id: "wwvFlowForm") ref_field = form.field_with(id: "STAND_REF") ref_field.value = ref resp = agent.submit form @array = hits resp sort end |
#select!(&block) ⇒ Object
34 35 36 37 |
# File 'lib/relaton/cen/hit_collection.rb', line 34 def select!(&block) @array.select!(&block) self end |