Class: BEL::Language::Term
- Inherits:
-
Object
- Object
- BEL::Language::Term
- Includes:
- Comparable
- Defined in:
- lib/bel/language.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#fx ⇒ Object
readonly
Returns the value of attribute fx.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Instance Method Summary collapse
-
#initialize(fx, *arguments) ⇒ Term
constructor
A new instance of Term.
- #to_s ⇒ Object
- #validate_signature ⇒ Object
Constructor Details
#initialize(fx, *arguments) ⇒ Term
Returns a new instance of Term.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/bel/language.rb', line 170 def initialize(fx, *arguments) @fx = fx @arguments = arguments ||= [] @signature = Signature.new( @fx.short_form, *@arguments.map { |arg| case arg when Term F.new(arg.fx.return_type) when Parameter E.new(arg.enc) when nil NullE.new end }) end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
168 169 170 |
# File 'lib/bel/language.rb', line 168 def arguments @arguments end |
#fx ⇒ Object (readonly)
Returns the value of attribute fx.
168 169 170 |
# File 'lib/bel/language.rb', line 168 def fx @fx end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
168 169 170 |
# File 'lib/bel/language.rb', line 168 def signature @signature end |
Instance Method Details
#to_s ⇒ Object
204 205 206 |
# File 'lib/bel/language.rb', line 204 def to_s "#{@fx.short_form}(#{@arguments.map(&:to_s).join(',')})" end |
#validate_signature ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/bel/language.rb', line 187 def validate_signature invalids = [] @arguments.select { |arg| Term === arg }.each do |term| invalids << term if not term.validate_signature end sigs = fx.signatures match = sigs.any? do |sig| (@signature <=> sig) >= 0 end invalids << self if not match if block_given? and not invalids.empty? invalids.each do |term| yield term, term.fx.signatures end end invalids.empty? end |