Module: Lydown::Parsing::RootMethods
- Included in:
- Barline, DurationMacroExpression, Root
- Defined in:
- lib/lydown/parsing/nodes.rb
Instance Method Summary collapse
- #_to_stream(element, stream, opts) ⇒ Object
- #add_event(stream, opts, type) ⇒ Object
- #each_child(ele = nil, &block) ⇒ Object
- #event_hash(stream, opts, hash = {}) ⇒ Object
- #to_stream(stream = [], opts = {}) ⇒ Object
Instance Method Details
#_to_stream(element, stream, opts) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/lydown/parsing/nodes.rb', line 3 def _to_stream(element, stream, opts) if element.elements element.elements.each do |e| e.respond_to?(:to_stream) ? e.to_stream(stream, opts) : _to_stream(e, stream, opts) end end stream end |
#add_event(stream, opts, type) ⇒ Object
53 54 55 |
# File 'lib/lydown/parsing/nodes.rb', line 53 def add_event(stream, opts, type) stream << event_hash(stream, opts, {type: type}) end |
#each_child(ele = nil, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/lydown/parsing/nodes.rb', line 14 def each_child(ele = nil, &block) ele ||= elements return unless ele ele.each do |e| block[e] if e.respond_to?(:to_stream) each_child(e.elements, &block) if e.elements end end |
#event_hash(stream, opts, hash = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lydown/parsing/nodes.rb', line 29 def event_hash(stream, opts, hash = {}) if opts[:proof_mode] && (source = opts[:source]) last = stream.last if last && (last[:type] == :source_ref) && last[:line] line, column = last[:line], last[:column] else line, column = source.find_line_and_column(interval.first) end hash.merge({ filename: opts[:filename], source: source, line: line, column: column }) else hash end ensure if $progress_bar $progress_bar.progress = (opts[:progress_base] || 0) + interval.end end end |
#to_stream(stream = [], opts = {}) ⇒ Object
24 25 26 27 |
# File 'lib/lydown/parsing/nodes.rb', line 24 def to_stream(stream = [], opts = {}) _to_stream(self, stream, opts) stream end |