Class: SourceTrack::TokenParser
- Inherits:
-
Object
- Object
- SourceTrack::TokenParser
- Defined in:
- lib/source_track/token_parser.rb
Instance Method Summary collapse
-
#encode(tokens) ⇒ Object
returns a string that can be set in the cookie we may or may not need to encode so the cookies work in all situations.
-
#parse(v) ⇒ Object
Take the string from the cookie and return the source tokens (token and optional date) ABC12300FA|CODE2300FB|CD2380 #( with dates, last 4 characters are hex ) ABBC123|CODE23|CD #( no dates ) we MUST preserve order.
Instance Method Details
#encode(tokens) ⇒ Object
returns a string that can be set in the cookie we may or may not need to encode so the cookies work in all situations
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/source_track/token_parser.rb', line 31 def encode(tokens) return nil if tokens.nil? tokens = [tokens] unless tokens.is_a?(Array) # TODO: tokens need to be unique (duplicates need to remain at the end), remember # the order from left to right is oldest to newest - any duplicates should always be newest # (i.e. if we 'track' a user using the same token on the same day 2x - the second visit's position # should be meaningful) -- i.e. order of tracking => A, F, B, F, C should encode as A|B|F|C, NOT A|F|B|C tokens.map{|t| encode_token(t) }.join(config.separator) end |
#parse(v) ⇒ Object
Take the string from the cookie and return the source tokens (token and optional date) ABC12300FA|CODE2300FB|CD2380 #( with dates, last 4 characters are hex ) ABBC123|CODE23|CD #( no dates ) we MUST preserve order
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/source_track/token_parser.rb', line 11 def parse(v) return [] if v.nil? || v.strip.empty? tokens = [] v.split(config.separator).each do |t| # validate the token is valid if config.use_dates? token, token_date = split_token_date(t, config.date_length) tokens << {:token => token, :date => get_date(token_date, config.epoch)} else tokens << {:token => t} end end tokens end |