Class: Glaemscribe::API::Mode
- Inherits:
-
Object
- Object
- Glaemscribe::API::Mode
- Defined in:
- lib/api/mode.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#default_charset ⇒ Object
Returns the value of attribute default_charset.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#human_name ⇒ Object
Returns the value of attribute human_name.
-
#language ⇒ Object
Returns the value of attribute language.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#post_processor ⇒ Object
Returns the value of attribute post_processor.
-
#pre_processor ⇒ Object
Returns the value of attribute pre_processor.
-
#processor ⇒ Object
Returns the value of attribute processor.
-
#supported_charsets ⇒ Object
Returns the value of attribute supported_charsets.
-
#version ⇒ Object
Returns the value of attribute version.
-
#warnings ⇒ Object
Returns the value of attribute warnings.
-
#writing ⇒ Object
Returns the value of attribute writing.
Instance Method Summary collapse
- #finalize(options = {}) ⇒ Object
-
#initialize(name) ⇒ Mode
constructor
A new instance of Mode.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #transcribe(content, charset = nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Mode
Returns a new instance of Mode.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/api/mode.rb', line 40 def initialize(name) @name = name @errors = [] @warnings = [] @supported_charsets = {} @options = {} @pre_processor = TranscriptionPreProcessor.new(self) @processor = TranscriptionProcessor.new(self) @post_processor = TranscriptionPostProcessor.new(self) end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
32 33 34 |
# File 'lib/api/mode.rb', line 32 def @authors end |
#default_charset ⇒ Object
Returns the value of attribute default_charset.
38 39 40 |
# File 'lib/api/mode.rb', line 38 def default_charset @default_charset end |
#errors ⇒ Object
Returns the value of attribute errors.
27 28 29 |
# File 'lib/api/mode.rb', line 27 def errors @errors end |
#human_name ⇒ Object
Returns the value of attribute human_name.
32 33 34 |
# File 'lib/api/mode.rb', line 32 def human_name @human_name end |
#language ⇒ Object
Returns the value of attribute language.
32 33 34 |
# File 'lib/api/mode.rb', line 32 def language @language end |
#name ⇒ Object
Returns the value of attribute name.
30 31 32 |
# File 'lib/api/mode.rb', line 30 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
35 36 37 |
# File 'lib/api/mode.rb', line 35 def @options end |
#post_processor ⇒ Object
Returns the value of attribute post_processor.
33 34 35 |
# File 'lib/api/mode.rb', line 33 def post_processor @post_processor end |
#pre_processor ⇒ Object
Returns the value of attribute pre_processor.
33 34 35 |
# File 'lib/api/mode.rb', line 33 def pre_processor @pre_processor end |
#processor ⇒ Object
Returns the value of attribute processor.
33 34 35 |
# File 'lib/api/mode.rb', line 33 def processor @processor end |
#supported_charsets ⇒ Object
Returns the value of attribute supported_charsets.
37 38 39 |
# File 'lib/api/mode.rb', line 37 def supported_charsets @supported_charsets end |
#version ⇒ Object
Returns the value of attribute version.
32 33 34 |
# File 'lib/api/mode.rb', line 32 def version @version end |
#warnings ⇒ Object
Returns the value of attribute warnings.
28 29 30 |
# File 'lib/api/mode.rb', line 28 def warnings @warnings end |
#writing ⇒ Object
Returns the value of attribute writing.
32 33 34 |
# File 'lib/api/mode.rb', line 32 def writing @writing end |
Instance Method Details
#finalize(options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/api/mode.rb', line 60 def finalize(={}) # Hash: option_name => value_name = {} # Build default options @options.each { |oname, o| [oname] = o.default_value_name } # Push user options .each { |oname, valname| # Check if option exists opt = @options[oname] next if(!opt) val = opt.value_for_value_name(valname) next if val == nil [oname] = valname } = {} # Do a conversion to values space .each{ |oname,valname| [oname] = @options[oname].value_for_value_name(valname) } @pre_processor.finalize() @post_processor.finalize() @processor.finalize() self end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/api/mode.rb', line 56 def inspect to_s end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/api/mode.rb', line 52 def to_s " <Mode #{name}: Language '#{language}', Writing '#{writing}', Human Name '#{human_name}', Authors '#{}', Version '#{version}'> " end |
#transcribe(content, charset = nil) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/api/mode.rb', line 96 def transcribe(content, charset = nil) charset = default_charset if !charset return false, "*** No charset usable for transcription. Failed!" if !charset ret = content.lines.map{ |l| l = l.strip # Clean the lines l = @pre_processor.apply(l) l = @processor.apply(l, charset) l = @post_processor.apply(l) }.join("\n") return true, ret end |