Class: TwitterCldr::Segmentation::Rule

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

Direct Known Subclasses

BreakRule, NoBreakRule

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ Rule

Returns a new instance of Rule.



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

def initialize(left, right)
  @left = left
  @right = right
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



15
16
17
# File 'lib/twitter_cldr/segmentation/rule.rb', line 15

def id
  @id
end

#leftObject (readonly)

Returns the value of attribute left.



14
15
16
# File 'lib/twitter_cldr/segmentation/rule.rb', line 14

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



14
15
16
# File 'lib/twitter_cldr/segmentation/rule.rb', line 14

def right
  @right
end

#stringObject

Returns the value of attribute string.



15
16
17
# File 'lib/twitter_cldr/segmentation/rule.rb', line 15

def string
  @string
end

Instance Method Details

#match(cursor) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/twitter_cldr/segmentation/rule.rb', line 22

def match(cursor)
  left_match = match_side(left, cursor.text, cursor.position)
  return nil unless left_match
  left_match_offset = offset(left_match, cursor.position)

  right_match = match_side(right, cursor.text, left_match_offset.last)
  return nil unless right_match
  right_match_offset = offset(right_match, left_match_offset.last)

  offset = [left_match_offset.first, right_match_offset.last]
  position = left_match_offset.last

  RuleMatchData.new(self, offset, position)
end