In Files

Parent

Included Modules

Files

TokenCounter

Counts the number of tokens in each line.

Attributes

current_file[R]

Public Class Methods

new() click to toggle source
# File lib/saikuro.rb, line 55
def initialize
  @files = Hash.new
  @tokens_per_line = Hash.new(0)
  @current_file = ""
end

Public Instance Methods

count_token(line_no,token) click to toggle source

Count the token for the passed line.

# File lib/saikuro.rb, line 82
def count_token(line_no,token)
  case token
  when TkSPACE, TkNL, TkRD_COMMENT
    # Do not count these as tokens
  when TkCOMMENT
    # Ignore this only for comments in a statement?
    # Ignore TkCOLON,TkCOLON2  and operators? like "." etc..
  when TkRBRACK, TkRPAREN, TkRBRACE
    # Ignore the closing of an array/index/hash/paren
    # The opening is counted, but no more.
    # Thus [], () {} is counted as 1 token not 2.
  else
    # may want to filter out comments...
    @tokens_per_line[line_no] += 1
  end
end
list_tokens_per_line(formater) click to toggle source

Iterate through all tracked files, passing the the provided formater the token counts.

# File lib/saikuro.rb, line 70
def list_tokens_per_line(formater)
  formater.start_count(@files.size)
  @files.each do |fname, tok_per_line|
    formater.start_file(fname)
    tok_per_line.sort.each do |line,num|
      formater.line_token_count(line,num)
    end
    formater.end_file
  end
end
set_current_file(file) click to toggle source

Mark file to associate with the token count.

# File lib/saikuro.rb, line 62
def set_current_file(file)
  @current_file = file
  @tokens_per_line = Hash.new(0)
  @files[@current_file] = @tokens_per_line
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.