Class: Refine::Blueprints::Blueprint
- Inherits:
-
Object
- Object
- Refine::Blueprints::Blueprint
- Defined in:
- app/models/refine/blueprints/blueprint.rb
Instance Attribute Summary collapse
-
#blueprint ⇒ Object
readonly
DSL-based model for building filter blueprints.
Instance Method Summary collapse
- #add(item) ⇒ Object
- #and ⇒ Object
- #conjunction(word) ⇒ Object
- #criterion(condition_id, input) ⇒ Object
- #group(&block) ⇒ Object
-
#initialize ⇒ Blueprint
constructor
A new instance of Blueprint.
- #or ⇒ Object
- #to_array ⇒ Object
Constructor Details
#initialize ⇒ Blueprint
Returns a new instance of Blueprint.
6 7 8 9 |
# File 'app/models/refine/blueprints/blueprint.rb', line 6 def initialize @blueprint = [] @depth = 0 end |
Instance Attribute Details
#blueprint ⇒ Object (readonly)
DSL-based model for building filter blueprints
4 5 6 |
# File 'app/models/refine/blueprints/blueprint.rb', line 4 def blueprint @blueprint end |
Instance Method Details
#add(item) ⇒ Object
50 51 52 |
# File 'app/models/refine/blueprints/blueprint.rb', line 50 def add(item) @blueprint.append(item) end |
#and ⇒ Object
40 41 42 43 |
# File 'app/models/refine/blueprints/blueprint.rb', line 40 def and conjunction("and") self end |
#conjunction(word) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/models/refine/blueprints/blueprint.rb', line 32 def conjunction(word) add({ depth: @depth, type: "conjunction", word: word }) end |
#criterion(condition_id, input) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/refine/blueprints/blueprint.rb', line 18 def criterion(condition_id, input) if !@blueprint.blank? && @blueprint.last[:type] == "criterion" raise "Conjunction missing" end add({ depth: @depth, type: "criterion", condition_id: condition_id, input: input, }) self end |
#group(&block) ⇒ Object
11 12 13 14 15 16 |
# File 'app/models/refine/blueprints/blueprint.rb', line 11 def group(&block) @depth = @depth += 1 instance_eval(&block) @depth = @depth -= 1 self end |
#or ⇒ Object
45 46 47 48 |
# File 'app/models/refine/blueprints/blueprint.rb', line 45 def or conjunction("or") self end |
#to_array ⇒ Object
54 55 56 |
# File 'app/models/refine/blueprints/blueprint.rb', line 54 def to_array @blueprint end |