Class: Ruleby::Steel::WhenProperty

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, &block) ⇒ WhenProperty

Returns a new instance of WhenProperty.



243
244
245
246
247
248
249
# File 'lib/dsl/steel.rb', line 243

def initialize(parent,name, &block)
 @tag = nil
 @name = name
 @references = nil
 @block = block
 @parent = parent
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



254
255
256
# File 'lib/dsl/steel.rb', line 254

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



253
254
255
# File 'lib/dsl/steel.rb', line 253

def name
  @name
end

#tagObject

Returns the value of attribute tag.



250
251
252
# File 'lib/dsl/steel.rb', line 250

def tag
  @tag
end

#typeObject

Returns the value of attribute type.



251
252
253
# File 'lib/dsl/steel.rb', line 251

def type
  @type
end

#valueObject

Returns the value of attribute value.



252
253
254
# File 'lib/dsl/steel.rb', line 252

def value
  @value
end

Instance Method Details

#&Object



256
257
258
# File 'lib/dsl/steel.rb', line 256

def &
  return @parent
end

#bind(n) ⇒ Object



260
261
262
# File 'lib/dsl/steel.rb', line 260

def bind(n)
  @tag = n
end

#not=(value, ref = nil) ⇒ Object



264
265
266
267
268
269
270
271
272
273
# File 'lib/dsl/steel.rb', line 264

def not=(value,ref=nil)
  if ref && ref == :%
    raise 'Using \'not=\' for references is not yet supported'
    set_block do |x,y| x != y end
    references value
  else        
    set_block do |s| s != value end
  end
  
end

#references(refs) ⇒ Object



279
280
281
# File 'lib/dsl/steel.rb', line 279

def references(refs)
  @references = refs
end

#to_atom(pattern_tags) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/dsl/steel.rb', line 283

def to_atom(pattern_tags)
  unless @tag
    @tag = GeneratedTag.new
  end
  if @references
    @references = [@references] unless @references.kind_of?(Array)
    i = includes_how_many(@references, pattern_tags.keys)
    if i == 0
      return Ruleby::Core::ReferenceAtom.new(@tag, @name, @references, @parent.type, &@block)
    elsif i == @references.size
      refs = @references.collect{|r| pattern_tags[r] }
      return Ruleby::Core::SelfReferenceAtom.new(@tag, @name, refs, @parent.type, &@block)
    else
      raise 'Referencing self AND other patterns in the same atom is not yet supported'
    end
  else  
    return Ruleby::Core::PropertyAtom.new(@tag, @name, @parent.type, &@block)
  end
end