Class: SmTranscript::SegReader
- Inherits:
-
Object
- Object
- SmTranscript::SegReader
- Defined in:
- lib/sm_transcript/seg_reader.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(xml_doc) ⇒ SegReader
constructor
A new instance of SegReader.
- #parse_metadata ⇒ Object
- #parse_words ⇒ Object
Constructor Details
#initialize(xml_doc) ⇒ SegReader
Returns a new instance of SegReader.
19 20 21 22 23 24 25 |
# File 'lib/sm_transcript/seg_reader.rb', line 19 def initialize(xml_doc) @metadata = {} @words = [] @root = xml_doc.root () parse_words() end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/sm_transcript/seg_reader.rb', line 11 def @metadata end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
12 13 14 |
# File 'lib/sm_transcript/seg_reader.rb', line 12 def words @words end |
Class Method Details
.from_file(file_name) ⇒ Object
14 15 16 17 |
# File 'lib/sm_transcript/seg_reader.rb', line 14 def self.from_file(file_name) # p File.expand_path(file_name) new(REXML::Document.new File.open(file_name)) end |
Instance Method Details
#parse_metadata ⇒ Object
27 28 29 30 31 |
# File 'lib/sm_transcript/seg_reader.rb', line 27 def () reg = Regexp.new('[\w\-_]*\.seg$') @metadata["orig_seg_path"] = # absolute path to segfile on processor reg.match(@root.attributes.get_attribute("fileName").value) end |
#parse_words ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sm_transcript/seg_reader.rb', line 33 def parse_words() # line is expected to contain two integers separated by a space, # followed by a space and one or more words. The words may contain # characters, or an apostrophe @root.elements.each("/document/lecture/segment") do |s| s.text.scan(/^\d* \d* [\w']*$/) do |t| arr = t.split @words << SmTranscript::Word.new(arr[0], arr[1], arr[1].to_i - arr[0].to_i, arr[2]) end end end |