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.
19 20 21 22 23 24 |
# File 'lib/sm_transcript/wrd_reader.rb', line 19 def initialize(src_file) @metadata = {} @words = [] () parse_words(src_file) end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/sm_transcript/wrd_reader.rb', line 11 def @metadata end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
12 13 14 |
# File 'lib/sm_transcript/wrd_reader.rb', line 12 def words @words end |
Class Method Details
.from_file(file_name) ⇒ Object
14 15 16 17 |
# File 'lib/sm_transcript/wrd_reader.rb', line 14 def self.from_file(file_name) # p File.expand_path(file_name) new(File.open(file_name)) end |
Instance Method Details
#parse_metadata ⇒ Object
26 27 28 |
# File 'lib/sm_transcript/wrd_reader.rb', line 26 def () # there is currently no metadata in .wrd files end |
#parse_words(src_file) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sm_transcript/wrd_reader.rb', line 30 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 or an apostrophe ln.scan(/^\d* \d* [\w']* *[\w']*/) do |t| arr = t.split @words << SmTranscript::Word.new(arr[0], arr[1], arr[2]) end end end |