class Greeb::Span

Greeb operates with spans. A span is a tuple of *(from, to, kind)*, where from is a beginning of the span, to is an ending of the span, and kind is a type of the span.

There are several span types: `:letter` for letters, `:float` for floating point decimals, `:integer` for numbers, `:separ` for separators, `:punct` for punctuation characters, `:spunct` for in-sentence punctuation characters, `:space` for spaces, and `:break` for line endings.

Public Class Methods

derivate(*members) click to toggle source

members. Useful in integrating with Greeb.

@param members [Array<Symbol>] additional members.

@return [Struct] a new structure.

# File lib/greeb/span.rb, line 18
def self.derivate(*members)
  Struct.new(*self.members, *members)
end

Public Instance Methods

<=>(other) click to toggle source

@private

# File lib/greeb/span.rb, line 33
def <=> other
  if (comparison = self.from <=> other.from) == 0
    self.to <=> other.to
  else
    comparison
  end
end
eql?(other) click to toggle source

@private

# File lib/greeb/span.rb, line 42
def eql? other
  return false unless type == other.type
  (self <=> other) == 0
end
slice(text) click to toggle source

Select the slice of the given text using coorinates of this span.

@param text [String] a text to be extracted.

@return [String] the retrieved substring.

# File lib/greeb/span.rb, line 28
def slice(text)
  text[from...to]
end