Class: GEDCOM::Parser
- Inherits:
-
Object
- Object
- GEDCOM::Parser
- Defined in:
- lib/gedcom_ruby.rb
Constant Summary collapse
- ANY =
[:any]
Instance Attribute Summary collapse
-
#auto_concat ⇒ Object
Returns the value of attribute auto_concat.
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #after(tags, callback = nil, &block) ⇒ Object
- #after_initialize ⇒ 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gedcom_ruby.rb', line 32 def initialize(&block) @callbacks = { :before => {}, :after => {} } @context_stack = [] @data_stack = [] @current_level = -1 @auto_concat = true instance_eval(&block) if block_given? after_initialize end |
Instance Attribute Details
#auto_concat ⇒ Object
Returns the value of attribute auto_concat.
28 29 30 |
# File 'lib/gedcom_ruby.rb', line 28 def auto_concat @auto_concat end |
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
29 30 31 |
# File 'lib/gedcom_ruby.rb', line 29 def callbacks @callbacks end |
Instance Method Details
#after(tags, callback = nil, &block) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/gedcom_ruby.rb', line 61 def after(, callback=nil, &block) = [].flatten callback = check_proc_or_block(callback, &block) @callbacks[:after][] = default_empty(@callbacks[:after][]) @callbacks[:after][].push(callback) end |
#after_initialize ⇒ Object
49 50 51 |
# File 'lib/gedcom_ruby.rb', line 49 def after_initialize # Template end |
#before(tags, callback = nil, &block) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/gedcom_ruby.rb', line 53 def before(, callback=nil, &block) = [].flatten callback = check_proc_or_block(callback, &block) @callbacks[:before][] = default_empty(@callbacks[:before][]) @callbacks[:before][].push(callback) end |
#context ⇒ Object
84 85 86 |
# File 'lib/gedcom_ruby.rb', line 84 def context @context_stack end |
#parse(file) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/gedcom_ruby.rb', line 69 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 |