Class: SmTranscript::WrdReader
- Inherits:
-
Object
- Object
- SmTranscript::WrdReader
- Defined in:
- lib/sm_transcript/wrd_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(src_file) ⇒ WrdReader
constructor
A new instance of WrdReader.
- #parse_metadata ⇒ Object
- #parse_words(src_file) ⇒ Object
Constructor Details
#initialize(src_file) ⇒ WrdReader
Returns a new instance of WrdReader.
21 22 23 24 25 26 |
# File 'lib/sm_transcript/wrd_reader.rb', line 21 def initialize(src_file) = {} @words = [] () parse_words(src_file) end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
13 14 15 |
# File 'lib/sm_transcript/wrd_reader.rb', line 13 def end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
14 15 16 |
# File 'lib/sm_transcript/wrd_reader.rb', line 14 def words @words end |
Class Method Details
.from_file(file_name) ⇒ Object
16 17 18 19 |
# File 'lib/sm_transcript/wrd_reader.rb', line 16 def self.from_file(file_name) # p File.expand_path(file_name) new(File.open(file_name)) end |
Instance Method Details
#parse_metadata ⇒ Object
28 29 30 |
# File 'lib/sm_transcript/wrd_reader.rb', line 28 def () # there is currently no metadata in .wrd files end |
#parse_words(src_file) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sm_transcript/wrd_reader.rb', line 32 def parse_words(src_file) src_file.each do |ln| # 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, an apostrophe, and, in some post-processed transcripts, # angle brackets. i.e. "<noise>" ln.scan(/^\d* \d* [\w'<>]* *[\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 |