class Typingpool::Config::Root::Assign::Qualification

Public Class Methods

new(spec) click to toggle source
# File lib/typingpool/config/root.rb, line 58
def initialize(spec)
  @raw = spec
  to_arg #make sure value parses
end

Public Instance Methods

to_arg() click to toggle source
# File lib/typingpool/config/root.rb, line 67
def to_arg
  [type, opts]
end
to_s() click to toggle source
# File lib/typingpool/config/root.rb, line 63
def to_s
  @raw
end

Protected Instance Methods

comparator(value) click to toggle source
# File lib/typingpool/config/root.rb, line 99
def comparator(value)
  Hash[
       '>' => :gt,
       '>=' => :gte,
       '<' => :lt,
       '<=' => :lte,
       '==' => :eql,
       '!=' => :not,
       'true' => :eql,
       'exists' => :exists
      ][value]
end
opts() click to toggle source
# File lib/typingpool/config/root.rb, line 87
def opts
  args = @raw.split(/\s+/)
  if (args.count > 3) || (args.count < 2)
    raise Error::Argument, "Unexpected number of qualification tokens: #{@raw}"
  end
  args.shift
  comparator(args[0]) or raise Error::Argument, "Unknown comparator '#{args[0]}'"
  value = 1
  value = args[1] if args.count == 2
  return {comparator(args[0]) => value}
end
type() click to toggle source
# File lib/typingpool/config/root.rb, line 73
def type
  type = @raw.split(/\s+/)[0]
  if RTurk::Qualification.types[type.to_sym]
    return type.to_sym
  elsif (type.match(/\d/) || type.size >= 25)
    return type
  else
    #Seems likely to be qualification typo: Not a known
    #system qualification, all letters and less than 25
    #chars
    raise Error::Argument, "Unknown qualification type and does not appear to be a raw qualification type ID: '#{type.to_s}'"
  end 
end