Module: RelatonIec
- Defined in:
- lib/relaton_iec/scrapper.rb,
lib/relaton_iec.rb,
lib/relaton_iec/hit.rb,
lib/relaton_iec/version.rb,
lib/relaton_iec/processor.rb,
lib/relaton_iec/xml_parser.rb,
lib/relaton_iec/hash_converter.rb,
lib/relaton_iec/hit_collection.rb,
lib/relaton_iec/iec_bibliography.rb,
lib/relaton_iec/iec_bibliographic_item.rb
Overview
Capybara.request_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new app, js_errors: false
end Capybara.default_driver = :poltergeist
Defined Under Namespace
Modules: Scrapper Classes: HashConverter, Hit, HitCollection, IecBibliographicItem, IecBibliography, Processor, XMLParser
Constant Summary collapse
- VERSION =
"1.7.8".freeze
Class Method Summary collapse
- .code_to_urn(code, lang = nil) ⇒ String?
-
.grammar_hash ⇒ String
Returns hash of XML reammar.
-
.urn_to_code(urn) ⇒ Array<String>?
Urn & language.
Class Method Details
.code_to_urn(code, lang = nil) ⇒ String?
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/relaton_iec.rb', line 26 def code_to_urn(code, lang = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength rest = code.downcase.sub(%r{ (?<head>[^\s]+)\s (?<type>is|ts|tr|pas|srd|guide|tec|wp)?(?(<type>)\s) (?<pnum>[\d-]+)\s? (?<_dd>:)?(?(<_dd>)(?<date>[\d-]+)\s?) }x, "") m = $~ return unless m[:head] && m[:pnum] deliv = /cmv|csv|exv|prv|rlv|ser/.match(code.downcase).to_s urn = ["urn", "iec", "std", m[:head].split("/").join("-"), m[:pnum], m[:date], m[:type], deliv, lang] (urn + ajunct_to_urn(rest)).join ":" end |
.grammar_hash ⇒ String
Returns hash of XML reammar
16 17 18 19 20 21 |
# File 'lib/relaton_iec.rb', line 16 def grammar_hash gem_path = File. "..", __dir__ grammars_path = File.join gem_path, "grammars", "*" grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join Digest::MD5.hexdigest grammars end |
.urn_to_code(urn) ⇒ Array<String>?
Returns urn & language.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/relaton_iec.rb', line 43 def urn_to_code(urn) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity fields = urn.upcase.split ":" return if fields.size < 5 head, num, date, type, deliv, lang = fields[3, 8] code = head.gsub("-", "/") code += " #{type}" unless type.nil? || type.empty? code += " #{num}" code += ":#{date}" unless date.nil? || date.empty? code += ajanct_to_code(fields[9..-1]) code += " #{deliv}" unless deliv.nil? || deliv.empty? [code, lang&.downcase] end |