Sha256: ba4a1e9d757b7ea1d10ce620310a3b049a0208fa4bdd9226bf6fdc562c67a73e

Contents?: true

Size: 561 Bytes

Versions: 10

Compression:

Stored size: 561 Bytes

Contents

module TextRank
  module RankFilter
    ##
    # A rank filter which sorts the results by value
    ##
    class SortByValue

      # @param descending [boolean] whether to sort in descending order
      def initialize(descending: true)
        @descending = !!descending
      end

      # Perform the filter on the ranks
      # @param ranks [Hash<String, Float>] the results of the PageRank algorithm
      # @return [Hash<String, Float>]
      def filter!(ranks, **_)
        Hash[ranks.sort_by { |_, v| @descending ? -v : v }]
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
text_rank-1.3.0 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.2.9 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.2.5 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.2.4 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.2.3 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.2.2 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.2.0 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.1.7 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.1.6 lib/text_rank/rank_filter/sort_by_value.rb
text_rank-1.1.5 lib/text_rank/rank_filter/sort_by_value.rb