Class: Ruleby::Ferrari::AtomBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl/ferrari.rb

Direct Known Subclasses

NotOperatorBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AtomBuilder

Returns a new instance of AtomBuilder.



186
187
188
189
190
191
192
# File 'lib/dsl/ferrari.rb', line 186

def initialize(name)   
  @name = name
  @deftemplate = nil
  @tag = nil
  @bindings = []
  @block = lambda {|x| true}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



194
195
196
197
198
# File 'lib/dsl/ferrari.rb', line 194

def method_missing(method_id, *args, &block)
  if method_id == :not
    return NotOperatorBuilder.new(@name)
  end
end

Instance Attribute Details

#bindingsObject

Returns the value of attribute bindings.



184
185
186
# File 'lib/dsl/ferrari.rb', line 184

def bindings
  @bindings
end

#blockObject

Returns the value of attribute block.



184
185
186
# File 'lib/dsl/ferrari.rb', line 184

def block
  @block
end

#deftemplateObject

Returns the value of attribute deftemplate.



184
185
186
# File 'lib/dsl/ferrari.rb', line 184

def deftemplate
  @deftemplate
end

#nameObject

Returns the value of attribute name.



184
185
186
# File 'lib/dsl/ferrari.rb', line 184

def name
  @name
end

#tagObject

Returns the value of attribute tag.



184
185
186
# File 'lib/dsl/ferrari.rb', line 184

def tag
  @tag
end

Instance Method Details

#<(value) ⇒ Object



210
211
212
# File 'lib/dsl/ferrari.rb', line 210

def <(value)
  create_block value, lambda {|x,y| x < y}, lambda {|x| x < value}; self
end

#<=(value) ⇒ Object



218
219
220
# File 'lib/dsl/ferrari.rb', line 218

def <=(value)
  create_block value, lambda {|x,y| x <= y}, lambda {|x| x <= value}; self
end

#==(value) ⇒ Object



200
201
202
203
204
# File 'lib/dsl/ferrari.rb', line 200

def ==(value)
  @atom_type = :equals
  @value = value
  create_block value, lambda {|x,y| x == y}, lambda {|x| x == value}; self
end

#=~(value) ⇒ Object



214
215
216
# File 'lib/dsl/ferrari.rb', line 214

def =~(value)
  create_block value, lambda {|x,y| x =~ y}, lambda {|x| x =~ value}; self
end

#>(value) ⇒ Object



206
207
208
# File 'lib/dsl/ferrari.rb', line 206

def >(value)
  create_block value, lambda {|x,y| x > y}, lambda {|x| x > value}; self
end

#>=(value) ⇒ Object



222
223
224
# File 'lib/dsl/ferrari.rb', line 222

def >=(value)
  create_block value, lambda {|x,y| x >= y}, lambda {|x| x >= value}; self
end

#build_atom(tags, methods, when_id) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/dsl/ferrari.rb', line 230

def build_atom(tags,methods,when_id)               
  if @bindings.empty?
    if @atom_type == :equals 
      return Core::EqualsAtom.new(@tag, @name, @deftemplate, @value) 
    else
      return Core::PropertyAtom.new(@tag, @name, @deftemplate, &@block) 
    end
  end
  
  if references_self?(tags,when_id)
    bind_methods = @bindings.collect{ |bb| methods[bb.tag] }
    Core::SelfReferenceAtom.new(@tag,@name,bind_methods,@deftemplate,&@block)
  else
    bind_tags = @bindings.collect{ |bb| bb.tag }
    Core::ReferenceAtom.new(@tag,@name,bind_tags,@deftemplate,&@block)
  end
end