Class: Bioinform::MotifModel::NamedModel

Inherits:
Object
  • Object
show all
Defined in:
lib/bioinform/data_models/named_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name) ⇒ NamedModel

Returns a new instance of NamedModel.



5
6
7
# File 'lib/bioinform/data_models/named_model.rb', line 5

def initialize(model, name)
  @model, @name = model, name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



19
20
21
22
23
24
25
26
# File 'lib/bioinform/data_models/named_model.rb', line 19

def method_missing(meth, *args, &block)
  result = model.public_send(meth, *args, &block)
  if motif?(result) && ! result.is_a?(self.class)
    self.class.new(result, name)
  else
    result
  end
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/bioinform/data_models/named_model.rb', line 4

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/bioinform/data_models/named_model.rb', line 4

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
# File 'lib/bioinform/data_models/named_model.rb', line 33

def ==(other)
  model == other.model && name == other.name
end

#to_sObject

should not be delegated to self (because in that case name won’t be displayed)



29
30
31
# File 'lib/bioinform/data_models/named_model.rb', line 29

def to_s
  MotifFormatter.new.format(self)
end