Class: LLT::Token::Word

Inherits:
LLT::Token show all
Defined in:
lib/llt/token/word.rb

Instance Attribute Summary

Attributes inherited from LLT::Token

#functions, #special_roles

Instance Method Summary collapse

Methods inherited from LLT::Token

#add_form, #add_forms, #has_special_role?, #initialize, #set_special_role

Constructor Details

This class inherits a constructor from LLT::Token

Instance Method Details

#delimiterObject



48
49
50
# File 'lib/llt/token/word.rb', line 48

def delimiter
  " | ".cyan
end

#enumeration(i) ⇒ Object



44
45
46
# File 'lib/llt/token/word.rb', line 44

def enumeration(i)
  "#{i}: ".light_yellow
end

#forms_to_sObject



31
32
33
34
35
36
37
38
# File 'lib/llt/token/word.rb', line 31

def forms_to_s
  # was each_with_index_and_object, which is currently not available
  @container.each_with_index.each_with_object("") do |(f, i), str|
    str << enumeration(i) << stripped_form(f)
    str << delimiter unless f == @container.last
    str
  end
end

#inspectObject



26
27
28
29
# File 'lib/llt/token/word.rb', line 26

def inspect
  "#{"Word token".green}: #{@string}\n" +
  "\tForms: #{forms_to_s}\n"
end

#no_forms?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/llt/token/word.rb', line 10

def no_forms?
  @container.empty?
end

#set_functionsObject



14
15
16
# File 'lib/llt/token/word.rb', line 14

def set_functions
  [:word]
end

#stripped_form(form) ⇒ Object



40
41
42
# File 'lib/llt/token/word.rb', line 40

def stripped_form(form)
  form.to_s.sub(@string, "").strip
end

#use(i = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/llt/token/word.rb', line 18

def use(i = nil)
  if i
    return @container[i - 1]
  elsif block_given?
    @container.find { |f| yield(f) }
  end
end

#wordObject



6
7
8
# File 'lib/llt/token/word.rb', line 6

def word
  @string
end