Class: JSONAPIonify::CharacterRange

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jsonapionify/character_range.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_char, end_char) ⇒ CharacterRange

Returns a new instance of CharacterRange.



11
12
13
14
15
16
17
# File 'lib/jsonapionify/character_range.rb', line 11

def initialize(start_char, end_char)
  if [start_char, end_char].any? { |c| c.length > 1 }
    raise ArgumentError, 'must be single characters'
  end
  @start_char = start_char
  @end_char   = end_char
end

Class Method Details

.[](*args) ⇒ Object



6
7
8
# File 'lib/jsonapionify/character_range.rb', line 6

def [](*args)
  new(*args)
end

Instance Method Details

#eachObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/jsonapionify/character_range.rb', line 19

def each
  range.each do |ord|
    begin
      char = ord.chr(Encoding::UTF_8)
      yield char
    rescue RangeError
      next
    end
  end
end

#to_aObject



30
31
32
# File 'lib/jsonapionify/character_range.rb', line 30

def to_a
  each.to_a
end