class OmniCat::Doc

Attributes

content[R]
content_md5[R]
count[R]
tokens[R]

Public Class Methods

new(doc_hash = {}) click to toggle source
# File lib/omnicat/doc.rb, line 9
def initialize(doc_hash = {})
  @auto_classified = doc_hash[:auto_classified] || false
  @content = doc_hash[:content]
  @content_md5 = doc_hash[:content_md5] || Digest::MD5.hexdigest("#{@content}")
  @count = (doc_hash[:count] || 1).to_i
  @tokens = tokenize_with_counts unless @tokens.is_a?(Hash)
end

Public Instance Methods

decrement_count() click to toggle source
# File lib/omnicat/doc.rb, line 21
def decrement_count
  @count -= 1 if @count > 0
end
increment_count() click to toggle source
# File lib/omnicat/doc.rb, line 17
def increment_count
  @count += 1
end

Private Instance Methods

exclude_tokens() click to toggle source

nodoc

# File lib/omnicat/doc.rb, line 41
def exclude_tokens
  OmniCat.config.exclude_tokens
end
minus_tokens() click to toggle source

nodoc

# File lib/omnicat/doc.rb, line 27
def minus_tokens
  body = @content
  OmniCat.config.token_patterns[:minus].each { |p| body.gsub!(p, ' ') }
  body
end
plus_tokens(body) click to toggle source

nodoc

# File lib/omnicat/doc.rb, line 34
def plus_tokens(body)
  body_tokens = []
  OmniCat.config.token_patterns[:plus].each { |p| body_tokens += body.scan(p) }
  body_tokens
end
tokenize() click to toggle source

nodoc

# File lib/omnicat/doc.rb, line 51
def tokenize
  plus_tokens(minus_tokens) - exclude_tokens
end
tokenize_with_counts() click to toggle source

nodoc

# File lib/omnicat/doc.rb, line 46
def tokenize_with_counts
  tokenize.hashify_with_counts
end