Sha256: 41e858de5560750a8e217c56be36234cafa29cc37b30a99513f4a7859667d36e

Contents?: true

Size: 640 Bytes

Versions: 16

Compression:

Stored size: 640 Bytes

Contents

module Dentaku
  class Token
    attr_reader :category, :raw_value, :value

    def initialize(category, value, raw_value = nil)
      @category  = category
      @value     = value
      @raw_value = raw_value
    end

    def to_s
      raw_value || value
    end

    def length
      raw_value.to_s.length
    end

    def empty?
      length.zero?
    end

    def grouping?
      is?(:grouping)
    end

    def is?(c)
      category == c
    end

    def ==(other)
      (category.nil? || other.category.nil? || category == other.category) &&
      (value.nil?    || other.value.nil?    || value    == other.value)
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
dentaku-3.5.3 lib/dentaku/token.rb
dentaku-3.5.2 lib/dentaku/token.rb
dentaku_zevo-3.5.2 lib/dentaku/token.rb
dentaku-3.5.1 lib/dentaku/token.rb
dentaku-3.5.0 lib/dentaku/token.rb
dentaku-3.4.2 lib/dentaku/token.rb
dentaku-3.4.1 lib/dentaku/token.rb
dentaku-3.4.0 lib/dentaku/token.rb
dentaku-3.3.4 lib/dentaku/token.rb
dentaku-3.3.3 lib/dentaku/token.rb
dentaku-3.3.2 lib/dentaku/token.rb
dentaku-3.3.1 lib/dentaku/token.rb
dentaku-3.3.0 lib/dentaku/token.rb
dentaku-3.2.1 lib/dentaku/token.rb
dentaku-3.2.0 lib/dentaku/token.rb
dentaku-3.1.0 lib/dentaku/token.rb