Class: Fop::Program

Inherits:
Object
  • Object
show all
Defined in:
lib/fop/program.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Program

Returns a new instance of Program.



8
9
10
11
# File 'lib/fop/program.rb', line 8

def initialize(src)
  tokens = Tokenizer.tokenize! src
  @nodes = Parser.parse! tokens
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



6
7
8
# File 'lib/fop/program.rb', line 6

def nodes
  @nodes
end

Instance Method Details

#apply(input) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/fop/program.rb', line 13

def apply(input)
  input = input.clone
  output =
    @nodes.reduce("") { |acc, token|
      section = token.consume!(input)
      return nil if section.nil?
      acc + section.to_s
    }
  input.empty? ? output : nil
end