Class: Pslm::PsalmPointer
- Inherits:
-
Object
- Object
- Pslm::PsalmPointer
- Defined in:
- lib/pslm/psalmpointer.rb
Overview
Workhorse of the pslm CLI utility.
Instance Method Summary collapse
-
#initialize(options) ⇒ PsalmPointer
constructor
A new instance of PsalmPointer.
- #process(psalm_files, output_file = nil, overwr_options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ PsalmPointer
Returns a new instance of PsalmPointer.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pslm/psalmpointer.rb', line 8 def initialize() @options = # make @options a StructuredSetup - because of deep #dup and recursive #update unless @options.is_a? StructuredSetup @options = StructuredSetup.new @options end @reader = PslmReader.new end |
Instance Method Details
#process(psalm_files, output_file = nil, overwr_options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pslm/psalmpointer.rb', line 19 def process(psalm_files, output_file=nil, ={}) = @options.dup .update if output_file != nil then outf = File.open output_file, 'w' else outf = STDOUT end unless psalm_files.is_a? Array psalm_files = [ psalm_files ] end psalms = psalm_files.collect do |pf| inf = open_psalm_file(pf) if [:input][:append] then inf = JoinedInput.new inf, StringIO.new([:input][:append]) end @reader.load_psalm(inf) end if [:input][:join] then while p = psalms.slice!(1) do psalms[0] += p end end if [:input][:title] then psalms.first.header.title = [:input][:title] # should it be set for all instead of for the first one only? end outputter = get_outputter [:general][:format] psalms.each do |ps| # yield the psalm before producing output to allow modification modified = yield ps if block_given? if modified != ps and modified.is_a?(Psalm) then ps = modified end outf.puts outputter.process_psalm ps, [:output] end if outf != STDOUT then outf.close end end |