Class: TSparser::AribStringDecoder::Definition::CodeOperator
- Inherits:
-
Object
- Object
- TSparser::AribStringDecoder::Definition::CodeOperator
- Defined in:
- lib/arib_string_decoder.rb
Instance Method Summary collapse
- #candidates(seq, set_map) ⇒ Object
-
#initialize ⇒ CodeOperator
constructor
A new instance of CodeOperator.
- #pull(seq, set_map) ⇒ Object
- #set(seq, set_name, group_name) ⇒ Object
Constructor Details
#initialize ⇒ CodeOperator
Returns a new instance of CodeOperator.
119 120 121 122 |
# File 'lib/arib_string_decoder.rb', line 119 def initialize @map = Hash.new @map_part = Hash.new{0} end |
Instance Method Details
#candidates(seq, set_map) ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/arib_string_decoder.rb', line 132 def candidates(seq, set_map) res = @map_part[seq] set_name, group_name = @map[seq[0..(seq.length-2)]] if set_name && set_map[set_name] && set_map[set_name].find_final_code(seq[-1]) res += 1 end return res end |
#pull(seq, set_map) ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/arib_string_decoder.rb', line 141 def pull(seq, set_map) set_name, group_name = @map[seq[0..(seq.length-2)]] raise "No operation match with #{seq}." unless set_name raise "Code set \"#{set_name}\" is undefined." unless set_map[set_name] code_name, byte_length = set_map[set_name].find_final_code(seq[-1]) raise "Terminal symbol \"#{seq[-1]}\" is not found." unless code_name return [code_name, group_name] end |
#set(seq, set_name, group_name) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/arib_string_decoder.rb', line 124 def set(seq, set_name, group_name) seq = seq[0..(seq.length-2)].map{|int| Binary.from_int(int)} @map[seq] = [set_name, group_name] seq.length.times do |i| @map_part[seq[0..i]] += 1 end end |