Class: Ruleby::Ferrari::AtomBuilder
- Inherits:
-
Object
- Object
- Ruleby::Ferrari::AtomBuilder
- Defined in:
- lib/dsl/ferrari.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bindings ⇒ Object
Returns the value of attribute bindings.
-
#block ⇒ Object
Returns the value of attribute block.
-
#deftemplate ⇒ Object
Returns the value of attribute deftemplate.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
- #<(value) ⇒ Object
- #<=(value) ⇒ Object
- #==(value) ⇒ Object
- #=~(value) ⇒ Object
- #>(value) ⇒ Object
- #>=(value) ⇒ Object
- #build_atoms(tags, methods, when_id) ⇒ Object
-
#initialize(method_id) ⇒ AtomBuilder
constructor
A new instance of AtomBuilder.
- #method_missing(method_id, *args, &block) ⇒ Object
Constructor Details
#initialize(method_id) ⇒ AtomBuilder
250 251 252 253 254 255 256 257 |
# File 'lib/dsl/ferrari.rb', line 250 def initialize(method_id) @name = method_id @deftemplate = nil @tag = GeneratedTag.new @bindings = [] @block = lambda {|x| true} @child_atom_builders = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args, &block) ⇒ Object
259 260 261 262 263 |
# File 'lib/dsl/ferrari.rb', line 259 def method_missing(method_id, *args, &block) if method_id == :not return NotOperatorBuilder.new(@name) end end |
Instance Attribute Details
#bindings ⇒ Object
Returns the value of attribute bindings.
248 249 250 |
# File 'lib/dsl/ferrari.rb', line 248 def bindings @bindings end |
#block ⇒ Object
Returns the value of attribute block.
248 249 250 |
# File 'lib/dsl/ferrari.rb', line 248 def block @block end |
#deftemplate ⇒ Object
Returns the value of attribute deftemplate.
248 249 250 |
# File 'lib/dsl/ferrari.rb', line 248 def deftemplate @deftemplate end |
#name ⇒ Object
Returns the value of attribute name.
248 249 250 |
# File 'lib/dsl/ferrari.rb', line 248 def name @name end |
#tag ⇒ Object
Returns the value of attribute tag.
248 249 250 |
# File 'lib/dsl/ferrari.rb', line 248 def tag @tag end |
Instance Method Details
#<(value) ⇒ Object
275 276 277 |
# File 'lib/dsl/ferrari.rb', line 275 def <(value) create_block value, lambda {|x,y| x < y}, lambda {|x| x < value}; self end |
#<=(value) ⇒ Object
283 284 285 |
# File 'lib/dsl/ferrari.rb', line 283 def <=(value) create_block value, lambda {|x,y| x <= y}, lambda {|x| x <= value}; self end |
#==(value) ⇒ Object
265 266 267 268 269 |
# File 'lib/dsl/ferrari.rb', line 265 def ==(value) @atom_type = :equals @value = value create_block value, lambda {|x,y| x == y}, lambda {|x| x == value}; self end |
#=~(value) ⇒ Object
279 280 281 |
# File 'lib/dsl/ferrari.rb', line 279 def =~(value) create_block value, lambda {|x,y| x =~ y}, lambda {|x| x =~ value}; self end |
#>(value) ⇒ Object
271 272 273 |
# File 'lib/dsl/ferrari.rb', line 271 def >(value) create_block value, lambda {|x,y| x > y}, lambda {|x| x > value}; self end |
#>=(value) ⇒ Object
287 288 289 |
# File 'lib/dsl/ferrari.rb', line 287 def >=(value) create_block value, lambda {|x,y| x >= y}, lambda {|x| x >= value}; self end |
#build_atoms(tags, methods, when_id) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/dsl/ferrari.rb', line 295 def build_atoms(,methods,when_id) atoms = @child_atom_builders.map { |atom_builder| [atom_builder.tag] = when_id methods[atom_builder.tag] = atom_builder.name atom_builder.build_atoms(,methods,when_id) }.flatten || [] if @bindings.empty? if @atom_type == :equals return atoms << Core::EqualsAtom.new(@tag, @name, @deftemplate, @value) else return atoms << Core::PropertyAtom.new(@tag, @name, @deftemplate, &@block) end end if references_self?(,when_id) bind_methods = @bindings.collect{ |bb| methods[bb.tag] } atoms << Core::SelfReferenceAtom.new(@tag,@name,bind_methods,@deftemplate,&@block) else = @bindings.collect{ |bb| bb.tag } atoms << Core::ReferenceAtom.new(@tag,@name,,@deftemplate,&@block) end end |