Module: Factbase::Term::Meta

Included in:
Factbase::Term
Defined in:
lib/factbase/terms/meta.rb

Overview

Meta terms.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Instance Method Details

#absent(fact, _maps) ⇒ Object



36
37
38
39
# File 'lib/factbase/terms/meta.rb', line 36

def absent(fact, _maps)
  assert_args(1)
  by_symbol(0, fact).nil?
end

#exists(fact, _maps) ⇒ Object



31
32
33
34
# File 'lib/factbase/terms/meta.rb', line 31

def exists(fact, _maps)
  assert_args(1)
  !by_symbol(0, fact).nil?
end

#many(fact, maps) ⇒ Object



62
63
64
65
66
# File 'lib/factbase/terms/meta.rb', line 62

def many(fact, maps)
  assert_args(1)
  v = the_values(0, fact, maps)
  !v.nil? && v.size > 1
end

#nil(fact, maps) ⇒ Object



57
58
59
60
# File 'lib/factbase/terms/meta.rb', line 57

def nil(fact, maps)
  assert_args(1)
  the_values(0, fact, maps).nil?
end

#one(fact, maps) ⇒ Object



68
69
70
71
72
# File 'lib/factbase/terms/meta.rb', line 68

def one(fact, maps)
  assert_args(1)
  v = the_values(0, fact, maps)
  !v.nil? && v.size == 1
end

#size(fact, _maps) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/factbase/terms/meta.rb', line 41

def size(fact, _maps)
  assert_args(1)
  v = by_symbol(0, fact)
  return 0 if v.nil?
  return 1 unless v.is_a?(Array)
  v.size
end

#type(fact, _maps) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/factbase/terms/meta.rb', line 49

def type(fact, _maps)
  assert_args(1)
  v = by_symbol(0, fact)
  return 'nil' if v.nil?
  v = v[0] if v.is_a?(Array) && v.size == 1
  v.class.to_s
end