Class: TwitterCldr::Segmentation::StateTable

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/segmentation/state_table.rb

Constant Summary collapse

PACK_FMT_16 =
's!*'.freeze
BOF_REQUIRED_FLAG =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, flags) ⇒ StateTable

Returns a new instance of StateTable.



25
26
27
28
# File 'lib/twitter_cldr/segmentation/state_table.rb', line 25

def initialize(values, flags)
  @values = values
  @flags = flags
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



23
24
25
# File 'lib/twitter_cldr/segmentation/state_table.rb', line 23

def flags
  @flags
end

#valuesObject (readonly)

Returns the value of attribute values.



23
24
25
# File 'lib/twitter_cldr/segmentation/state_table.rb', line 23

def values
  @values
end

Class Method Details

.load16(hash) ⇒ Object



15
16
17
18
19
20
# File 'lib/twitter_cldr/segmentation/state_table.rb', line 15

def load16(hash)
  new(
    Base64.decode64(hash[:table]).unpack(PACK_FMT_16),
    hash[:flags]
  )
end

Instance Method Details

#[](idx) ⇒ Object



30
31
32
# File 'lib/twitter_cldr/segmentation/state_table.rb', line 30

def [](idx)
  values[idx]
end

#bof_required?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/twitter_cldr/segmentation/state_table.rb', line 34

def bof_required?
  flags & BOF_REQUIRED_FLAG != 0
end

#dump16Object



38
39
40
41
42
43
# File 'lib/twitter_cldr/segmentation/state_table.rb', line 38

def dump16
  {
    table: Base64.encode64(values.pack(PACK_FMT_16)).strip,
    flags: flags
  }
end