Module: Factbase::Term::Strings
- Included in:
- Factbase::Term
- Defined in:
- lib/factbase/terms/strings.rb
Overview
String terms.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
Instance Method Details
#concat(fact, maps) ⇒ Object
31 32 33 |
# File 'lib/factbase/terms/strings.rb', line 31 def concat(fact, maps) (0..@operands.length - 1).map { |i| the_values(i, fact, maps)&.first }.join end |
#matches(fact, maps) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/factbase/terms/strings.rb', line 41 def matches(fact, maps) assert_args(2) str = the_values(0, fact, maps) return false if str.nil? raise 'Exactly one string expected' unless str.size == 1 re = the_values(1, fact, maps) raise 'Regexp is nil' if re.nil? raise 'Exactly one regexp expected' unless re.size == 1 str[0].to_s.match?(re[0]) end |
#sprintf(fact, maps) ⇒ Object
35 36 37 38 39 |
# File 'lib/factbase/terms/strings.rb', line 35 def sprintf(fact, maps) fmt = the_values(0, fact, maps)[0] ops = (1..@operands.length - 1).map { |i| the_values(i, fact, maps)&.first } format(*([fmt] + ops)) end |