class FindT::FileScanner

Constants

YAML_HASH_PATTERN

Public Class Methods

new(file) click to toggle source
# File lib/find_t/file_scanner.rb, line 6
def initialize(file)
  @file = file
end

Public Instance Methods

find(scopes) click to toggle source
# File lib/find_t/file_scanner.rb, line 10
def find(scopes)
  @scopes = scopes
  @size   = @scopes.size - 1

  @current_level  = 0
  @current_locale = nil
  @founds         = []

  File.open(@file) do |f|
    f.each_line.with_index do |line, n|
      scan_line line, n
    end
  end

  @founds
end
scan_line(line, n) click to toggle source
# File lib/find_t/file_scanner.rb, line 27
def scan_line(line, n)
  return unless line =~ YAML_HASH_PATTERN

  indent, scope, text = $1, $3, $4
  level = indent.size >> 1

  if level == 0 && text == ''
    @current_locale = scope
    @current_level  = 1
  elsif level == @current_level
    if scope == current_scope
      if level == @size
        @founds << {
          locale: @current_locale,
          file:   @file,
          line:   n + 1,
          text:   text,
        }
      elsif '' == text
        @current_level = level + 1
      end
    end
  elsif level < @current_level
    @current_level = level
  end
end

Private Instance Methods

current_scope() click to toggle source
# File lib/find_t/file_scanner.rb, line 54
        def current_scope
  @scopes[@current_level]
end