Class: TextRank::RankFilter::SortByValue
- Inherits:
-
Object
- Object
- TextRank::RankFilter::SortByValue
- Defined in:
- lib/text_rank/rank_filter/sort_by_value.rb
Overview
A rank filter which sorts the results by value
Instance Method Summary collapse
-
#filter!(ranks, **_) ⇒ Hash<String, Float>
Perform the filter on the ranks.
-
#initialize(descending: true) ⇒ SortByValue
constructor
A new instance of SortByValue.
Constructor Details
#initialize(descending: true) ⇒ SortByValue
Returns a new instance of SortByValue.
9 10 11 |
# File 'lib/text_rank/rank_filter/sort_by_value.rb', line 9 def initialize(descending: true) @descending = !!descending end |
Instance Method Details
#filter!(ranks, **_) ⇒ Hash<String, Float>
Perform the filter on the ranks
16 17 18 |
# File 'lib/text_rank/rank_filter/sort_by_value.rb', line 16 def filter!(ranks, **_) Hash[ranks.sort_by { |_, v| @descending ? -v : v }] end |