Class: RelatonItu::HitCollection
- Inherits:
-
Array
- Object
- Array
- RelatonItu::HitCollection
- Defined in:
- lib/relaton_itu/hit_collection.rb
Overview
Page of hit collection.
Constant Summary collapse
- DOMAIN =
"https://www.itu.int".freeze
Instance Attribute Summary collapse
- #fetched ⇒ TrueClass, FalseClass readonly
- #text ⇒ String readonly
- #year ⇒ String readonly
Instance Method Summary collapse
- #fetch ⇒ RelatonItu::HitCollection
-
#initialize(ref_nbr, year = nil) ⇒ HitCollection
constructor
A new instance of HitCollection.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ref_nbr, year = nil) ⇒ HitCollection
Returns a new instance of HitCollection.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/relaton_itu/hit_collection.rb', line 23 def initialize(ref_nbr, year = nil) #(text, hit_pages = nil) @text = ref_nbr @year = year # from, to = nil # if year # from = Date.strptime year, "%Y" # to = from.next_year.prev_day # end group = %r{(OB|Operational Bulletin) No} =~ text ? "Publications" : "Recommendations" url = "#{DOMAIN}/net4/ITU-T/search/GlobalSearch/Search" params = { "Input" => ref_nbr, "Start" => 0, "Rows" => 10, "SortBy" => "RELEVANCE", "ExactPhrase" => false, "CollectionName" => "General", "CollectionGroup" => group, "Sector" => "t", "Criterias" => [{ "Name" => "Search in", "Criterias" => [ { "Selected" => false, "Value" => "", "Label" => "Name", "Target" => "/name_s", "TypeName" => "CHECKBOX", "GetCriteriaType" => 0, }, { "Selected" => false, "Value" => "", "Label" => "Short description", "Target" => "/short_description_s", "TypeName" => "CHECKBOX", "GetCriteriaType" => 0, }, { "Selected" => false, "Value" => "", "Label" => "File content", "Target" => "/file", "TypeName" => "CHECKBOX", "GetCriteriaType" => 0, }, ], "ShowCheckbox" => true, "Selected" => false, }], "Topics" => "", "ClientData" => { "ip" => "" }, "Language" => "en", "IP" => "", "SearchType" => "All", } data = { json: params.to_json } resp = Net::HTTP.post(URI(url), data.to_json, "Content-Type" => "application/json") doc = JSON.parse resp.body hits = doc["results"].map do |h| code = h["Media"]["Name"] title = h["Title"] url = h["Redirection"] type = group.downcase[0...-1] Hit.new({ code: code, title: title, url: url, type: type }, self) end concat hits @fetched = false end |
Instance Attribute Details
#fetched ⇒ TrueClass, FalseClass (readonly)
13 14 15 |
# File 'lib/relaton_itu/hit_collection.rb', line 13 def fetched @fetched end |
#text ⇒ String (readonly)
16 17 18 |
# File 'lib/relaton_itu/hit_collection.rb', line 16 def text @text end |
#year ⇒ String (readonly)
19 20 21 |
# File 'lib/relaton_itu/hit_collection.rb', line 19 def year @year end |
Instance Method Details
#fetch ⇒ RelatonItu::HitCollection
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/relaton_itu/hit_collection.rb', line 94 def fetch workers = RelatonBib::WorkersPool.new 4 workers.worker(&:fetch) each do |hit| workers << hit end workers.end workers.result @fetched = true self end |
#inspect ⇒ Object
110 111 112 |
# File 'lib/relaton_itu/hit_collection.rb', line 110 def inspect "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>" end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/relaton_itu/hit_collection.rb', line 106 def to_s inspect end |