class RelatonItu::HitCollection

Page of hit collection.

Constants

DOMAIN

Attributes

agent[R]

@return [Mechanize]

gi_imp[R]

@return [TrueClass, FalseClass]

Public Class Methods

new(ref, year = nil) click to toggle source

@param ref [String] @param year [String]

Calls superclass method
# File lib/relaton_itu/hit_collection.rb, line 20
def initialize(ref, year = nil) # rubocop:todo Metrics/MethodLength
  text = ref.sub(/(?<=\.)Imp\s?(?=\d)/, "")
  super text, year
  @agent = Mechanize.new
  agent.user_agent_alias = "Mac Safari"
  @gi_imp = /\.Imp\d/.match?(ref)

  case ref
  when /^(ITU-T|ITU-R\sRR)/
    request_search
  when /^ITU-R\s/
    request_document(ref)
  end
end

Private Instance Methods

group() click to toggle source

@return [String]

# File lib/relaton_itu/hit_collection.rb, line 65
def group
  @group ||= case text
             when %r{OB|Operational Bulletin}, %r{^ITU-R\sRR}
               "Publications"
             when %r{^ITU-T} then "Recommendations"
             end
end
hits(data) click to toggle source

@param data [Hash] @return [Array<RelatonItu::Hit>]

# File lib/relaton_itu/hit_collection.rb, line 124
def hits(data)
  data["results"].map do |h|
    code  = h["Media"]["Name"]
    title = h["Title"]
    url   = h["Redirection"]
    type  = h["Collection"]["Group"].downcase[0...-1]
    Hit.new({ code: code, title: title, url: url, type: type }, self)
  end
end
params() click to toggle source

@return [Hash]

# File lib/relaton_itu/hit_collection.rb, line 74
def params # rubocop:disable Metrics/MethodLength
  {
    "Input" => text,
    "Start" => 0,
    "Rows" => 10,
    "SortBy" => "RELEVANCE",
    "ExactPhrase" => false,
    "CollectionName" => "General",
    "CollectionGroup" => group,
    "Sector" => text.match(/(?<=^ITU-)\w/).to_s.downcase,
    "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" => {},
    "Language" => "en",
    "SearchType" => "All",
  }
end
request_document(ref) click to toggle source

@param ref [String] a document ref

# File lib/relaton_itu/hit_collection.rb, line 45
def request_document(ref) # rubocop:todo Metrics/MethodLength
  uri = URI::HTTPS.build(
    host: "raw.githubusercontent.com",
    path: "/relaton/relaton-data-itu-r/master/data/#{ref.gsub(/[\s.]/, '_')}.yaml",
  )
  resp = Net::HTTP.get_response(uri)
  if resp.code == "404"
    @array = []
    return
  end

  hash = YAML.safe_load resp.body
  item_hash = HashConverter.hash_to_bib(hash)
  item = ItuBibliographicItem.new(**item_hash)
  hit = Hit.new({ url: uri.to_s }, self)
  hit.fetch = item
  @array = [hit]
end