Class: Protos::TokenList

Inherits:
Object
  • Object
show all
Defined in:
lib/protos/token_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens = []) ⇒ TokenList

Returns a new instance of TokenList.



10
11
12
# File 'lib/protos/token_list.rb', line 10

def initialize(tokens = [])
  @tokens = Set.new(tokens)
end

Instance Attribute Details

#tokensObject (readonly)

DOCS: A list of utility tokens that can handle parsing and merging sets of tokens together safely.



8
9
10
# File 'lib/protos/token_list.rb', line 8

def tokens
  @tokens
end

Instance Method Details

#add(tokens) ⇒ Object



27
28
29
30
# File 'lib/protos/token_list.rb', line 27

def add(tokens)
  @tokens.merge(parse(tokens))
  self
end

#clearObject



32
33
34
35
# File 'lib/protos/token_list.rb', line 32

def clear
  @tokens.clear
  self
end

#empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/protos/token_list.rb', line 14

def empty?
  @tokens.empty?
end

#remove(tokens) ⇒ Object



22
23
24
25
# File 'lib/protos/token_list.rb', line 22

def remove(tokens)
  @tokens.subtract(parse(tokens))
  self
end

#to_sObject



18
19
20
# File 'lib/protos/token_list.rb', line 18

def to_s
  @tokens.join(" ")
end