Class: TwitterCldr::Segmentation::RuleSet

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale, rules, boundary_type, options) ⇒ RuleSet

Returns a new instance of RuleSet.



21
22
23
24
25
26
27
28
# File 'lib/twitter_cldr/segmentation/rule_set.rb', line 21

def initialize(locale, rules, boundary_type, options)
  @locale = locale
  @rules = rules
  @boundary_type = boundary_type
  @use_uli_exceptions = options.fetch(
    :use_uli_exceptions, false
  )
end

Instance Attribute Details

#boundary_typeObject (readonly)

Returns the value of attribute boundary_type.



16
17
18
# File 'lib/twitter_cldr/segmentation/rule_set.rb', line 16

def boundary_type
  @boundary_type
end

#localeObject (readonly)

Returns the value of attribute locale.



16
17
18
# File 'lib/twitter_cldr/segmentation/rule_set.rb', line 16

def locale
  @locale
end

#rulesObject (readonly)

Returns the value of attribute rules.



16
17
18
# File 'lib/twitter_cldr/segmentation/rule_set.rb', line 16

def rules
  @rules
end

#use_uli_exceptionsObject Also known as: use_uli_exceptions?

Returns the value of attribute use_uli_exceptions.



17
18
19
# File 'lib/twitter_cldr/segmentation/rule_set.rb', line 17

def use_uli_exceptions
  @use_uli_exceptions
end

Class Method Details

.load(*args) ⇒ Object



11
12
13
# File 'lib/twitter_cldr/segmentation/rule_set.rb', line 11

def load(*args)
  RuleSetBuilder.load(*args)
end

Instance Method Details

#each_boundary(str) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/twitter_cldr/segmentation/rule_set.rb', line 30

def each_boundary(str)
  if block_given?
    cursor = Cursor.new(str)
    last_boundary = 0

    # implicit start of text boundary
    yield 0

    until cursor.eof?
      match = find_match(cursor)
      rule = match.rule

      if rule.break?
        yield match.boundary_position
        last_boundary = match.boundary_position
      end

      if match.boundary_position == cursor.position
        cursor.advance
      else
        cursor.advance(
          match.boundary_position - cursor.position
        )
      end
    end

    # implicit end of text boundary
    yield str.size unless last_boundary == str.size
  else
    to_enum(__method__, str)
  end
end