Sha256: 25dce51810922119a43804fd8bd2f034cfe5834fe3f549312576b91852d426e4

Contents?: true

Size: 1.63 KB

Versions: 17

Compression:

Stored size: 1.63 KB

Contents

module RelatonJis
  class Hit < RelatonBib::Hit
    #
    # Create new hit
    #
    # @param [Nokogiri::XML::Element] node found node
    # @param [RelatonJis::HitCollection] collection hit collection
    #
    # @return [RelatonJis::Hit] new hit
    #
    def self.create(node, collection)
      a = node.at("./a")
      hit = { id: a.at("./text()").text.strip, url: a["href"] }
      new hit, collection
    end

    #
    # Check if hit matches reference
    #
    # @param [Hash] ref_parts parts of reference
    # @param [String, nil] year year
    # @param [Boolean] all_parts check all parts of reference
    #
    # @return [Boolean] true if hit matches reference
    #
    def eq?(ref_parts, year = nil, all_parts: false) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
      id_parts[:code].include?(ref_parts[:code]) &&
        (all_parts || (ref_parts[:part].nil? || ref_parts[:part] == id_parts[:part])) &&
        (year.nil? || year == id_parts[:year]) &&
        ((ref_parts[:expl].nil? || !id_parts[:expl].nil?) &&
         (ref_parts[:expl_num].nil? || ref_parts[:expl_num] == id_parts[:expl_num])) &&
        ((ref_parts[:amd].nil? || !id_parts[:amd].nil?) &&
          (ref_parts[:amd_num].nil? || ref_parts[:amd_num] == id_parts[:amd_num]) &&
          (ref_parts[:amd_year].nil? || ref_parts[:amd_year] == id_parts[:amd_year]))
    end

    #
    # Return parts of document id
    #
    # @return [Hash] hash with parts of document id
    #
    def id_parts
      @id_parts ||= hit_collection.parse_ref hit[:id]
    end

    def fetch
      @fetch ||= Scraper.new(hit[:url]).fetch
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
relaton-jis-1.19.1 lib/relaton_jis/hit.rb
relaton-jis-1.19.0 lib/relaton_jis/hit.rb
relaton-jis-1.18.1 lib/relaton_jis/hit.rb
relaton-jis-1.18.0 lib/relaton_jis/hit.rb
relaton-jis-1.17.0 lib/relaton_jis/hit.rb
relaton-jis-1.16.8 lib/relaton_jis/hit.rb
relaton-jis-1.16.7 lib/relaton_jis/hit.rb
relaton-jis-1.16.6 lib/relaton_jis/hit.rb
relaton-jis-1.16.5 lib/relaton_jis/hit.rb
relaton-jis-1.16.4 lib/relaton_jis/hit.rb
relaton-jis-1.16.3 lib/relaton_jis/hit.rb
relaton-jis-1.16.2 lib/relaton_jis/hit.rb
relaton-jis-1.16.1 lib/relaton_jis/hit.rb
relaton-jis-1.16.0 lib/relaton_jis/hit.rb
relaton-jis-1.14.4 lib/relaton_jis/hit.rb
relaton-jis-1.14.3 lib/relaton_jis/hit.rb
relaton-jis-1.14.2 lib/relaton_jis/hit.rb