Class: Runestone::WebSearch::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/runestone/web_search/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, prefix: false, negative: false, alts: nil) ⇒ Token

Returns a new instance of Token.



3
4
5
6
7
8
# File 'lib/runestone/web_search/token.rb', line 3

def initialize(value, prefix: false, negative: false, alts: nil)
  @value = value
  @prefix = prefix
  @negative = negative
  @alts = alts || []
end

Instance Attribute Details

#altsObject

Returns the value of attribute alts.



2
3
4
# File 'lib/runestone/web_search/token.rb', line 2

def alts
  @alts
end

#negativeObject

Returns the value of attribute negative.



2
3
4
# File 'lib/runestone/web_search/token.rb', line 2

def negative
  @negative
end

#prefixObject

Returns the value of attribute prefix.



2
3
4
# File 'lib/runestone/web_search/token.rb', line 2

def prefix
  @prefix
end

#valueObject

Returns the value of attribute value.



2
3
4
# File 'lib/runestone/web_search/token.rb', line 2

def value
  @value
end

Instance Method Details

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/runestone/web_search/token.rb', line 10

def to_s
  if negative
    "!#{value}"
  elsif prefix
    if alts.empty?
      "#{value}:*"
    else
      "(#{value}:* | #{alts.join(' | ')})"
    end
  else
    if alts.empty?
      value
    else
      "(#{value} | #{alts.join(' | ')})"
    end
  end
end