Class: FactDb::Temporal::QueryBuilder
- Inherits:
-
Object
- Object
- FactDb::Temporal::QueryBuilder
- Defined in:
- lib/fact_db/temporal/query_builder.rb
Overview
A scoped query builder for temporal queries. Allows chaining: facts.at(“2024-01-15”).query(“Paula’s role”)
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
Instance Method Summary collapse
-
#compare_to(other_date, topic: nil) ⇒ Hash
Compare this date to another.
-
#facts(format: :json, **options) ⇒ Array, ...
Get all facts valid at this date.
-
#facts_for(entity_id, format: :json, **options) ⇒ Array, ...
Get facts for a specific entity at this date.
-
#initialize(facts, date) ⇒ QueryBuilder
constructor
Initialize with a Facts instance and date.
-
#query(topic, format: :json, **options) ⇒ Array, ...
Execute a query at this point in time.
-
#state_for(entity_id, format: :json) ⇒ Array
Get the timeline state at this date.
Constructor Details
#initialize(facts, date) ⇒ QueryBuilder
Initialize with a Facts instance and date
20 21 22 23 |
# File 'lib/fact_db/temporal/query_builder.rb', line 20 def initialize(facts, date) @facts = facts @date = date end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
14 15 16 |
# File 'lib/fact_db/temporal/query_builder.rb', line 14 def date @date end |
Instance Method Details
#compare_to(other_date, topic: nil) ⇒ Hash
Compare this date to another
56 57 58 |
# File 'lib/fact_db/temporal/query_builder.rb', line 56 def compare_to(other_date, topic: nil) @facts.diff(topic, from: @date, to: other_date) end |
#facts(format: :json, **options) ⇒ Array, ...
Get all facts valid at this date
38 39 40 |
# File 'lib/fact_db/temporal/query_builder.rb', line 38 def facts(format: :json, **) @facts.facts_at(@date, format: format, **) end |
#facts_for(entity_id, format: :json, **options) ⇒ Array, ...
Get facts for a specific entity at this date
47 48 49 |
# File 'lib/fact_db/temporal/query_builder.rb', line 47 def facts_for(entity_id, format: :json, **) @facts.facts_at(@date, entity: entity_id, format: format, **) end |
#query(topic, format: :json, **options) ⇒ Array, ...
Execute a query at this point in time
30 31 32 |
# File 'lib/fact_db/temporal/query_builder.rb', line 30 def query(topic, format: :json, **) @facts.query_facts(topic: topic, at: @date, format: format, **) end |
#state_for(entity_id, format: :json) ⇒ Array
Get the timeline state at this date
64 65 66 |
# File 'lib/fact_db/temporal/query_builder.rb', line 64 def state_for(entity_id, format: :json) @facts.facts_at(@date, entity: entity_id, format: format) end |