Class: TwitterCldr::Shared::UnicodeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/shared/unicode_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial = []) ⇒ UnicodeSet

Returns a new instance of UnicodeSet.



12
13
14
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 12

def initialize(initial = [])
  @set = TwitterCldr::Utils::RangeSet.from_array(initial)
end

Instance Attribute Details

#setObject (readonly)

Returns the value of attribute set.



10
11
12
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 10

def set
  @set
end

Instance Method Details

#add(codepoint) ⇒ Object



36
37
38
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 36

def add(codepoint)
  add_range(codepoint..codepoint)
end

#add_list(list) ⇒ Object



50
51
52
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 50

def add_list(list)
  set.union!(self.class.new(list).set)
end

#add_range(range) ⇒ Object



40
41
42
43
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 40

def add_range(range)
  set << range
  self
end

#add_set(unicode_set) ⇒ Object



45
46
47
48
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 45

def add_set(unicode_set)
  set.union!(unicode_set.set)
  self
end

#apply_pattern(pattern) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 16

def apply_pattern(pattern)
  re = TwitterCldr::Shared::UnicodeRegex.compile(pattern)

  re.elements.each do |element|
    element.to_set.ranges.each do |range|
      set << range
    end
  end

  self
end

#apply_property(property_name, property_value = nil) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 28

def apply_property(property_name, property_value = nil)
  set.union!(
    TwitterCldr::Shared::CodePoint.properties.code_points_for_property(
      property_name, property_value
    )
  )
end

#each(&block) ⇒ Object



63
64
65
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 63

def each(&block)
  set.each(&block)
end

#include?(codepoint) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 67

def include?(codepoint)
  set.include?(codepoint)
end

#subtract(codepoint) ⇒ Object



54
55
56
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 54

def subtract(codepoint)
  subtract_range(codepoint..codepoint)
end

#subtract_range(range) ⇒ Object



58
59
60
61
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 58

def subtract_range(range)
  set.subtract!(TwitterCldr::Utils::RangeSet.new([range]))
  self
end

#to_setObject



71
72
73
# File 'lib/twitter_cldr/shared/unicode_set.rb', line 71

def to_set
  set.to_set
end