Class: Bvh::Parser
- Inherits:
-
Object
- Object
- Bvh::Parser
- Defined in:
- lib/bvh/parser.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(file) ⇒ Parser
constructor
A new instance of Parser.
- #parse(bvh) ⇒ Object
Constructor Details
#initialize(file) ⇒ Parser
Returns a new instance of Parser.
6 7 8 9 |
# File 'lib/bvh/parser.rb', line 6 def initialize(file) @filename = file @source = File.read(file) end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/bvh/parser.rb', line 3 def filename @filename end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/bvh/parser.rb', line 4 def source @source end |
Instance Method Details
#parse(bvh) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bvh/parser.rb', line 11 def parse(bvh) @bvh = bvh # a little touch-up... s = source # it's tempting to just downcase the whole string, but that'd change the case of object names, which might be # bad for the end user. So we'll swap out specific keywords instead. s.gsub!(/^((\s*)(root|offset|channels|joint|end site|hierarchy)(([^\n\{]*)(\n|\{)))/mi) do match = $~ "#{match[2]}#{match[3].downcase.gsub(/\s/, '_')} \"#{match[5].strip}\"#{match[6]}" end # make { . . . } into proper Ruby blocks s.gsub!(/[\n\s]*\{/m, ' do').gsub!(/[\n\s]*\}/m, "\nend") # Finally, handle the MOTION segment, which can be treated as a single method call. s.gsub!(/^((\s*)(motion)(.*))/mi) do "#{$~[2]}#{$~[3].downcase} <<-EOF\n#{$~[4].strip}\nEOF\n" end eval(s, binding, @filename, 1) end |