Class: Freql::Rank

Inherits:
Object
  • Object
show all
Defined in:
lib/freql/rank.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ranksObject (readonly)

Returns the value of attribute ranks.



17
18
19
# File 'lib/freql/rank.rb', line 17

def ranks
  @ranks
end

Class Method Details

.by_lang(lang, size: :small) ⇒ Object



10
11
12
13
14
# File 'lib/freql/rank.rb', line 10

def by_lang lang, size: :small
  rank = self.new
  rank.extract_lang_file lang, size: size
  return rank
end

Instance Method Details

#extract_lang_file(lang, size:) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/freql/rank.rb', line 27

def extract_lang_file lang, size:
  BinData.read_lang( lang, size: size ) do |lang_data|
    # @ranks = lang_data.filter {|group| !group.empty? }
    # some words really should have the same ranking as the score is the same.
    # for now ignore that detail and build a simple flat list.
    # Its also wirth noting that the data contains non-words like 000.
    @ranks = lang_data.flatten
  end
end

#lookup(rank) ⇒ Object



19
20
21
# File 'lib/freql/rank.rb', line 19

def lookup rank
  @ranks[rank-1]
end

#top_n(rank) ⇒ Object



23
24
25
# File 'lib/freql/rank.rb', line 23

def top_n rank
  @ranks[0...rank]
end