Class: Greeb::Span

Inherits:
Struct
  • Object
show all
Defined in:
lib/greeb/span.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fromObject

Returns the value of attribute from

Returns:

  • (Object)

    the current value of from


10
11
12
# File 'lib/greeb/span.rb', line 10

def from
  @from
end

#toObject

Returns the value of attribute to

Returns:

  • (Object)

    the current value of to


10
11
12
# File 'lib/greeb/span.rb', line 10

def to
  @to
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type


10
11
12
# File 'lib/greeb/span.rb', line 10

def type
  @type
end

Class Method Details

.derivate(*members) ⇒ Struct

Create a deriviative structure that is based on Greeb::Span members. Useful in integrating with Greeb.

Parameters:

  • members (Array<Symbol>)

    additional members.

Returns:

  • (Struct)

    a new structure.


18
19
20
# File 'lib/greeb/span.rb', line 18

def self.derivate(*members)
  Struct.new(*self.members, *members)
end

Instance Method Details

#<=>(other) ⇒ Object


33
34
35
36
37
38
39
# 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) ⇒ Boolean

Returns:

  • (Boolean)

42
43
44
45
# File 'lib/greeb/span.rb', line 42

def eql? other
  return false unless type == other.type
  (self <=> other) == 0
end

#slice(text) ⇒ String

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

Parameters:

  • text (String)

    a text to be extracted.

Returns:

  • (String)

    the retrieved substring.


28
29
30
# File 'lib/greeb/span.rb', line 28

def slice(text)
  text[from...to]
end