Class: Transcribe::Term
- Inherits:
-
Object
- Object
- Transcribe::Term
- Defined in:
- lib/transcribe/term.rb
Constant Summary collapse
- WORD_BOUNDARY =
"\\b"- REPETITION =
"+"
Class Method Summary collapse
Instance Method Summary collapse
- #apply!(text) ⇒ Object
-
#initialize(from, to, opts = {}) ⇒ Term
constructor
A new instance of Term.
Constructor Details
#initialize(from, to, opts = {}) ⇒ Term
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/transcribe/term.rb', line 16 def initialize(from, to, opts = {}) @to = to if opts.empty? @from = from else from = Regexp.escape(from) flags = "" from.concat REPETITION if opts["repeatable"] from.prepend WORD_BOUNDARY if opts["word_initial"] from.concat WORD_BOUNDARY if opts["word_final"] @from = Regexp.new(from, flags) end end |
Class Method Details
.create_from_yaml(yaml) ⇒ Object
10 11 12 13 |
# File 'lib/transcribe/term.rb', line 10 def create_from_yaml(yaml) from, to = yaml.shift Term.new from, to, yaml end |
Instance Method Details
#apply!(text) ⇒ Object
30 31 32 |
# File 'lib/transcribe/term.rb', line 30 def apply!(text) text.gsub! @from, @to end |