Class: Yome::Parser
- Inherits:
-
Object
- Object
- Yome::Parser
- Defined in:
- lib/yome/parser.rb
Instance Attribute Summary collapse
-
#chips ⇒ Object
readonly
Returns the value of attribute chips.
-
#file_hash ⇒ Object
readonly
Returns the value of attribute file_hash.
Instance Method Summary collapse
- #collect_chips(dir) ⇒ Object
-
#initialize(dir) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(dir) ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 12 13 |
# File 'lib/yome/parser.rb', line 8 def initialize(dir) @file_hash = {} @chips = [] collect_chips(dir) end |
Instance Attribute Details
#chips ⇒ Object (readonly)
Returns the value of attribute chips.
6 7 8 |
# File 'lib/yome/parser.rb', line 6 def chips @chips end |
#file_hash ⇒ Object (readonly)
Returns the value of attribute file_hash.
6 7 8 |
# File 'lib/yome/parser.rb', line 6 def file_hash @file_hash end |
Instance Method Details
#collect_chips(dir) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 |