Class: Okura::Words::CompactStringArray

Inherits:
Object
  • Object
show all
Defined in:
lib/okura.rb

Defined Under Namespace

Classes: Builder

Instance Method Summary collapse

Constructor Details

#initialize(str, indices) ⇒ CompactStringArray

Returns a new instance of CompactStringArray.



109
110
111
112
# File 'lib/okura.rb', line 109

def initialize str,indices
  @str=str
  @indices=indices
end

Instance Method Details

#[](id) ⇒ Object



119
120
121
# File 'lib/okura.rb', line 119

def [](id)
  get id
end

#get(id) ⇒ Object



113
114
115
116
117
118
# File 'lib/okura.rb', line 113

def get id
  raise 'bad id' unless id < @indices.length
  from=@indices[id]
  to=(id+1 < @indices.length) ? @indices[id+1] : @str.bytesize
  (from...to).map{|i|@str.getbyte(i)}.pack('C*').force_encoding 'UTF-8'
end