Class: NRB::Untappd::API::URLTokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/drink-socially/api/url_tokenizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ URLTokenizer

Returns a new instance of URLTokenizer.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/drink-socially/api/url_tokenizer.rb', line 8

def initialize(args)
  @map = args[:map]
  @string = args[:string]
  raise ArgumentError unless @map && @string
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



6
7
8
# File 'lib/drink-socially/api/url_tokenizer.rb', line 6

def map
  @map
end

#stringObject (readonly)

Returns the value of attribute string.



6
7
8
# File 'lib/drink-socially/api/url_tokenizer.rb', line 6

def string
  @string
end

Instance Method Details

#trObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/drink-socially/api/url_tokenizer.rb', line 15

def tr
  return @string unless @string =~ /:[#{word_chars}]+:/
  result = ""
  s = StringScanner.new(@string)
  until s.eos? do
    word = s.scan(/:[#{word_chars}]+:|[#{url_chars}]+/)
    raise RuntimeError.new("String Scanner failed. File a bug.") if word.nil?
    result += tr_word(word)
  end
  result
end