class Yome::Parser

Attributes

chips[R]
file_hash[R]

Public Class Methods

new(dir) click to toggle source
# File lib/yome/parser.rb, line 8
def initialize(dir)
  @file_hash = {}
  @chips = []

  collect_chips(dir)
end

Public Instance Methods

collect_chips(dir) click to toggle source
# File lib/yome/parser.rb, line 15
def collect_chips(dir)
  Dir.chdir(dir) do
    Find.find(".") do |path|
      Find.prune if Lib::ignore?(File.basename(path))
      next if FileTest.directory?(path) || Lib::binary?(path)
  
      begin
        contents = File.read(path).split("\n")
      rescue ArgumentError
        STDERR.puts "Skip: #{path}"
        next
      end
  
      contents.each_with_index do |line, i|
        if line =~ /YOME:/
          path = path.gsub(/^\.\//, "")
          @file_hash[path] = contents
          @chips << Chip.new(line, path, i)
        end
      end 
    end
  end
end