Class: GEDCOM::Parser
- Inherits:
-
Object
- Object
- GEDCOM::Parser
- Defined in:
- lib/gedcom_ruby.rb
Instance Method Summary collapse
- #after(tags, callback = nil, &block) ⇒ Object
- #before(tags, callback = nil, &block) ⇒ Object
- #context ⇒ Object
-
#initialize(&block) ⇒ Parser
constructor
A new instance of Parser.
- #parse(file) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Parser
Returns a new instance of Parser.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gedcom_ruby.rb', line 29 def initialize(&block) @callbacks = { :before => Hash.new{|h,k| h[k] = []}, # Default to an empty array :after => Hash.new{|h,k| h[k] = []} # Default to an empty array } @context_stack = [] @data_stack = [] @current_level = -1 @auto_concat = true instance_eval(&block) if block_given? end |
Instance Method Details
#after(tags, callback = nil, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/gedcom_ruby.rb', line 50 def after(, callback=nil, &block) = [].flatten callback = check_proc_or_block(callback, &block) @callbacks[:after][].push(callback) end |
#before(tags, callback = nil, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/gedcom_ruby.rb', line 44 def before(, callback=nil, &block) = [].flatten callback = check_proc_or_block(callback, &block) @callbacks[:before][].push(callback) end |
#context ⇒ Object
71 72 73 |
# File 'lib/gedcom_ruby.rb', line 71 def context @context_stack end |
#parse(file) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gedcom_ruby.rb', line 56 def parse(file) case file when String if file =~ /\n/mo parse_string(file) else parse_file(file) end when IO parse_io(file) else raise ArgumentError.new("requires a String or IO") end end |