Class: Twitter::TwitterText::WeightedRange

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter-text/weighted_range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range = {}) ⇒ WeightedRange

Returns a new instance of WeightedRange.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/twitter-text/weighted_range.rb', line 12

def initialize(range = {})
  raise ArgumentError.new("Invalid range") unless [:start, :end, :weight].all? { |key| range.key?(key) && range[key].is_a?(Integer) }
  @start = range[:start]
  @end = range[:end]
  @weight = range[:weight]
end

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



10
11
12
# File 'lib/twitter-text/weighted_range.rb', line 10

def end
  @end
end

#startObject (readonly)

Returns the value of attribute start.



10
11
12
# File 'lib/twitter-text/weighted_range.rb', line 10

def start
  @start
end

#weightObject (readonly)

Returns the value of attribute weight.



10
11
12
# File 'lib/twitter-text/weighted_range.rb', line 10

def weight
  @weight
end

Instance Method Details

#contains?(code_point) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/twitter-text/weighted_range.rb', line 19

def contains?(code_point)
  code_point >= @start && code_point <= @end
end