Class: Glaemscribe::API::Mode
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.
-
#invention ⇒ Object
Returns the value of attribute invention.
-
#language ⇒ Object
Returns the value of attribute language.
-
#latest_option_values ⇒ Object
readonly
Returns the value of attribute latest_option_values.
-
#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.
-
#raw_mode_name ⇒ Object
Read from glaeml.
-
#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.
-
#world ⇒ Object
Returns the value of attribute world.
-
#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
- #raw_mode ⇒ Object
- #replace_specials(l) ⇒ Object
- #strict_transcribe(content, charset = nil) ⇒ Object
- #to_s ⇒ Object
- #transcribe(content, charset = nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Mode
Returns a new instance of Mode.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/api/mode.rb', line 46 def initialize(name) @name = name @errors = [] @warnings = [] @supported_charsets = {} = {} = nil @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 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 |
#invention ⇒ Object
Returns the value of attribute invention.
42 43 44 |
# File 'lib/api/mode.rb', line 42 def invention @invention end |
#language ⇒ Object
Returns the value of attribute language.
32 33 34 |
# File 'lib/api/mode.rb', line 32 def language @language end |
#latest_option_values ⇒ Object (readonly)
Returns the value of attribute latest_option_values.
44 45 46 |
# File 'lib/api/mode.rb', line 44 def latest_option_values @latest_option_values 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 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 |
#raw_mode_name ⇒ Object
Read from glaeml
40 41 42 |
# File 'lib/api/mode.rb', line 40 def raw_mode_name @raw_mode_name 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 |
#world ⇒ Object
Returns the value of attribute world.
42 43 44 |
# File 'lib/api/mode.rb', line 42 def world @world 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
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/api/mode.rb', line 67 def finalize(={}) if == # Small optimization : don't refinalize if options are the same as before return end = # Hash: option_name => value_name = {} # Build default options .each { |oname, o| [oname] = o.default_value_name } # Push user options .each { |oname, valname| # Check if option exists opt = [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] = [oname].value_for_value_name(valname) } # Add the option defined constants to the whole list for evaluation purposes .each { |oname, o| # For enums, add the values as constants for the evaluator if(o.type == Option::Type::ENUM) o.values.each{ |name, val| [name] = val } end } @latest_option_values = @pre_processor.finalize(@latest_option_values) @post_processor.finalize(@latest_option_values) @processor.finalize(@latest_option_values) raw_mode.finalize if raw_mode self end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/api/mode.rb', line 63 def inspect to_s end |
#raw_mode ⇒ Object
124 125 126 127 128 129 |
# File 'lib/api/mode.rb', line 124 def raw_mode return @raw_mode if @raw_mode loaded_raw_mode = (@raw_mode_name && Glaemscribe::API::ResourceManager.loaded_modes[@raw_mode_name]) return nil if !loaded_raw_mode @raw_mode = loaded_raw_mode.deep_clone end |
#replace_specials(l) ⇒ Object
131 132 133 134 135 |
# File 'lib/api/mode.rb', line 131 def replace_specials(l) l. gsub("_",SPECIAL_CHAR_UNDERSCORE). gsub("\u00a0",SPECIAL_CHAR_NBSP) end |
#strict_transcribe(content, charset = nil) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/api/mode.rb', line 137 def strict_transcribe(content, charset = nil) charset = default_charset if !charset return false, "*** No charset usable for transcription. Failed!" if !charset # Parser works line by line ret = content.lines.map{ |l| restore_lf = false if l[-1] == "\n" l[-1] = "" restore_lf = true end l = @pre_processor.apply(l) l = replace_specials(l) l = @processor.apply(l) l = @post_processor.apply(l, charset) l += "\n" if restore_lf l }.join return true, ret end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/api/mode.rb', line 59 def to_s " <Mode #{name}: Language '#{language}', Writing '#{writing}', Human Name '#{human_name}', Authors '#{authors}', Version '#{version}'> " end |
#transcribe(content, charset = nil) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/api/mode.rb', line 158 def transcribe(content, charset = nil) if raw_mode chunks = content.split(/({{.*?}})/m) ret = '' res = true chunks.each{ |c| if c =~ /{{(.*?)}}/m succ, r = raw_mode.strict_transcribe($1,charset) res = res && succ ret += r if succ else succ, r = strict_transcribe(c,charset) res = res && succ ret += r if succ end } return res,ret else strict_transcribe(content,charset) end end |