class SetBuilder::Trait
Attributes
direct_object_type[R]
modifiers[R]
name[R]
part_of_speech[R]
Public Class Methods
new(name, part_of_speech, *args, &block)
click to toggle source
# File lib/set_builder/trait.rb, line 10 def initialize(name, part_of_speech, *args, &block) case name when Hash @name, @direct_object_type = name.first[0].to_s, name.first[1] else @name = name.to_s end @part_of_speech, @block = part_of_speech, block @modifiers = (args||[]).collect {|modifier| Modifier[modifier]} end
Public Instance Methods
apply(*args)
click to toggle source
# File lib/set_builder/trait.rb, line 67 def apply(*args) SetBuilder::Constraint.new(self, *args, &@block) end
noun?()
click to toggle source
# File lib/set_builder/trait.rb, line 34 def noun? (self.part_of_speech == :noun) end
requires_direct_object?()
click to toggle source
# File lib/set_builder/trait.rb, line 27 def requires_direct_object? !@direct_object_type.nil? end
Also aliased as: direct_object_required?
to_json()
click to toggle source
# File lib/set_builder/trait.rb, line 57 def to_json array = [] array << (requires_direct_object? ? [name, @direct_object_type] : name) array << part_of_speech array << modifiers.collect{|klass| Modifier.name(klass)} unless modifiers.empty? array.to_json end
to_s(negative=false)
click to toggle source
# File lib/set_builder/trait.rb, line 40 def to_s(negative=false) case part_of_speech when :active negative ? "who have not #{name}" : "who #{name}" when :perfect negative ? "who have not #{name}" : "who have #{name}" when :passive negative ? "who were not #{name}" : "who were #{name}" when :reflexive negative ? "who are not #{name}" : "who are #{name}" when :noun "whose #{name}" end end