Class: Factbase::Fact
- Inherits:
-
Object
- Object
- Factbase::Fact
- Defined in:
- lib/factbase/fact.rb
Overview
A single fact in a factbase.
This is an internal class, it is supposed to be instantiated only by the Factbase
class. However, it is possible to use it for testing directly, for example to make a fact with a single key/value pair inside:
require 'factbase/fact'
f = Factbase::Fact.new({ 'foo' => [42, 256, 'Hello, world!'] })
assert_equal(42, f.foo)
A fact is basically a key/value hash map, where values are non-empty sets of values.
It is NOT thread-safe!
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#all_properties ⇒ Array<String>
Get a list of all props.
-
#initialize(map) ⇒ Fact
constructor
Ctor.
-
#to_s ⇒ String
Convert it to a string.
Constructor Details
#initialize(map) ⇒ Fact
Ctor.
33 34 35 |
# File 'lib/factbase/fact.rb', line 33 def initialize(map) @map = map end |
Instance Method Details
#all_properties ⇒ Array<String>
Get a list of all props.
45 46 47 |
# File 'lib/factbase/fact.rb', line 45 def all_properties @map.keys end |
#to_s ⇒ String
Convert it to a string.
39 40 41 |
# File 'lib/factbase/fact.rb', line 39 def to_s "[ #{@map.map { |k, v| "#{k}: #{v}" }.sort.join(', ')} ]" end |