Class: PPRB::PPRB
- Inherits:
-
Object
- Object
- PPRB::PPRB
- Defined in:
- lib/pprb.rb
Constant Summary collapse
- PROFILES =
{ :default => { :block => /^%(.*)/, :line => /^>(.*)/, :end => /^-$/, :ticks => /`(.*?)`/ }, :c_parsable => { :block => %r[^//\s*%(.*)], :line => %r[^//\s*>(.*)], :end => %r[^//\s*-$], :ticks => /\brb_(\w+?)_\b/ }, }
Instance Attribute Summary collapse
-
#ruby_output ⇒ Object
readonly
Returns the value of attribute ruby_output.
-
#target_output ⇒ Object
readonly
Returns the value of attribute target_output.
Instance Method Summary collapse
- #config(options) ⇒ Object
-
#initialize(source, start_state = :pp) ⇒ PPRB
constructor
source is either a File object or a string start_state is either :pp or :rb.
- #profile(filter = nil, prof = nil, overlay = nil) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(source, start_state = :pp) ⇒ PPRB
source is either a File object or a string start_state is either :pp or :rb
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pprb.rb', line 21 def initialize source, start_state = :pp @source = source @path = File.(source.path) if source.class == File @BLOCK = @LINE = @END = @TICKS = '' profile :default @ruby_output = '' @target_output = '' @input_state = [start_state] @last_emitted = :code load_rules source.lines.each { |l| process_line l } @ruby_output << ']' if @last_emitted == :text end |
Instance Attribute Details
#ruby_output ⇒ Object (readonly)
Returns the value of attribute ruby_output.
44 45 46 |
# File 'lib/pprb.rb', line 44 def ruby_output @ruby_output end |
#target_output ⇒ Object (readonly)
Returns the value of attribute target_output.
44 45 46 |
# File 'lib/pprb.rb', line 44 def target_output @target_output end |
Instance Method Details
#config(options) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/pprb.rb', line 85 def config for key, value in var = "@#{key.to_s.upcase}" raise "Unknown option: #{key}" if instance_variable_get(var) == nil instance_variable_set var, value end end |
#profile(filter = nil, prof = nil, overlay = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pprb.rb', line 62 def profile filter = nil, prof = nil, = nil # sort-out the passed arguments = filter if filter.class == Hash = prof if prof.class == Hash prof = filter if filter.class == Symbol filter = nil if filter != nil and filter.class != String prof = nil if prof != nil and prof.class != Symbol raise "No profile or overlay specified" if == nil and prof == nil unless filter if prof profile = PROFILES[prof] raise "Unknown profile: #{p}" if profile == nil config profile end config if else profile nil, prof, if File.fnmatch(filter, @path) end end |
#run ⇒ Object
39 40 41 42 |
# File 'lib/pprb.rb', line 39 def run run_and_translate_errors @ruby_output @target_output end |