class Furi::QueryToken

Attributes

name[R]
value[R]

Public Class Methods

new(name, value) click to toggle source
# File lib/furi/query_token.rb, line 26
def initialize(name, value)
  @name = name
  @value = value
end
parse(token) click to toggle source
# File lib/furi/query_token.rb, line 5
def self.parse(token)
  case token
  when QueryToken
    token
  when String
    key, value = token.split('=', 2).map do |s|
      ::URI.decode_www_form_component(s)
    end
    key ||= ""
    new(key, value)
  when Array
    QueryToken.new(*token)
  else
    raise_parse_error(token)
  end
end
raise_parse_error(token) click to toggle source
# File lib/furi/query_token.rb, line 22
def self.raise_parse_error(token)
  raise QueryParseError, "Can not parse query token #{token.inspect}"
end

Public Instance Methods

==(other) click to toggle source
# File lib/furi/query_token.rb, line 35
def ==(other)
  other = self.class.parse(other)
  return false unless other
  to_s == other.to_s
end
as_json(options = nil) click to toggle source
# File lib/furi/query_token.rb, line 49
def as_json(options = nil)
  to_a
end
inspect() click to toggle source
# File lib/furi/query_token.rb, line 53
def inspect
  [name, value].join('=')
end
to_a() click to toggle source
# File lib/furi/query_token.rb, line 31
def to_a
  [name, value]
end
to_s() click to toggle source
# File lib/furi/query_token.rb, line 41
def to_s
  encoded_key = ::URI.encode_www_form_component(name.to_s)

  !value.nil? ?
    "#{encoded_key}=#{::URI.encode_www_form_component(value.to_s)}" :
    encoded_key
end