Class: CipherBureau::Statistic

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/cipher_bureau/statistic.rb

Overview

Copyright © 2013 Dynamic Project Management AS Copyright © 2013 Knut I. Stenmark

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Class Method Summary collapse

Class Method Details

.register(word) ⇒ Object

register updates word statistics



28
29
30
31
32
33
34
# File 'lib/cipher_bureau/statistic.rb', line 28

def register(word)
  stat = where(:country_code => word.country_code, :grammar => word.grammar, :name_type => word.name_type, 
    :ascii => word.ascii, :length => word.word.length).first_or_initialize
  stat.word_count += 1
  stat.save!
  stat
end

.word_count(*args) ⇒ Object

returns number of words indatabase based on selection criteria

Examples:
  word_count(5) => number of words with length 5
  word_count(:ascii => true)  number of wordss with true ascii
  word_count(5, :ascii => true)  number of wordsof length 5, with true ascii


42
43
44
45
46
# File 'lib/cipher_bureau/statistic.rb', line 42

def word_count(*args)
  criteria = args.extract_options!
  criteria.merge!(:length => args.first) if args.first
  where(criteria).sum(:word_count)
end