Class: Factbase::TermBase

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/terms/base.rb

Overview

Base class for all terms.

Instance Method Summary collapse

Instance Method Details

#to_sString

Turns it into a string.

Returns:

  • (String)

    The string of it



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/factbase/terms/base.rb', line 15

def to_s
  @to_s ||=
    begin
      items = []
      items << @op
      items +=
        @operands.map do |o|
          if o.is_a?(String)
            "'#{o.gsub("'", "\\\\'").gsub('"', '\\\\"')}'"
          elsif o.is_a?(Time)
            o.utc.iso8601
          else
            o.to_s
          end
        end
      "(#{items.join(' ')})"
    end
end