class Riseup::Spec

Attributes

regex[R]
tokens[R]

Public Class Methods

new(spec) click to toggle source
# File lib/riseup/spec.rb, line 5
def initialize(spec)
  unless spec.is_a?(Array)
    raise ArgumentError, 'Specification must be an array'
  end
  spec.each_with_index do |i, j|
    unless i.is_a?(Array)
      raise ArgumentError, "Specification item #{j} must be an array"
    end
    if i.size < 2
      raise ArgumentError, "Specification item #{j} is too small, must contain at least 2 items"
    end
    if i.size > 3
      raise ArgumentError, "Specification item #{j} is too largw, must contain no more than 3 items"
    end
  end
  @spec = spec
  @spec_map = Hash[@spec.collect { |t| [t[0], TokenData.new(t[1], t[2])] }]
  @tokens = @spec.map { |t| t[0] }
  # (?x)
  @regex = Regexp.new('(' + (@tokens.map { |t| Regexp.escape(t) }).join('|') + '|[.])')
end

Public Instance Methods

[](key) click to toggle source
# File lib/riseup/spec.rb, line 27
def [](key)
  @spec_map[key]
end
include?(x) click to toggle source
# File lib/riseup/spec.rb, line 31
def include?(x)
  @spec_map.include?(x)
end