public
Description: Life On The Edge With Merb, DataMapper & RSpec
Homepage: http://blog.new-bamboo.co.uk
Clone URL: git://github.com/deimos1986/book_mdar.git
book_mdar / book_builder / file_finder.rb
100644 19 lines (17 sloc) 0.431 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module BookBuilder
  class FileFinder < Array
    def initialize(root_path, format)
      @format = format.to_s
      @root = root_path.to_s
      super(Dir["#{@root}**/*.#{@format}"].entries)
    end
  
    def contents
      self.map do |path|
        File.open(path,'r') { |f| f.read }
      end
    end
  
    def merged_contents
      self.contents.inject('') { |merged,content| merged << content << "\n" }
    end
  end
end