Class: CBETA::CharFrequency

Inherits:
Object
  • Object
show all
Defined in:
lib/cbeta/char_freq.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml_root, opts = {}) ⇒ CharFrequency

Returns a new instance of CharFrequency.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :top (Integer)


3
4
5
6
7
8
9
10
11
# File 'lib/cbeta/char_freq.rb', line 3

def initialize(xml_root, opts={})
  @xml_root = xml_root
  @config = {
    top: 10
  }
  @config.merge!(opts)
  @result = {}
  @current = @result
end

Instance Method Details

#char_freq(canon = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/cbeta/char_freq.rb', line 13

def char_freq(canon=nil)
  stat_all if canon.nil?
  stat_canon(canon)
  r = @result.sort_by {|k,v| v}
  r[(0-@config[:top])..-1].reverse
end