Class: RedBlocks::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/red_blocks/expression.rb

Direct Known Subclasses

ComposedExpression

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, score: nil, weight: 1, label: nil) ⇒ Expression

Returns a new instance of Expression.



5
6
7
8
9
10
# File 'lib/red_blocks/expression.rb', line 5

def initialize(key, score: nil, weight: 1, label: nil)
  @score = score
  @weight = weight
  @key   = key
  @label = label
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/red_blocks/expression.rb', line 3

def key
  @key
end

#labelObject

Returns the value of attribute label.



3
4
5
# File 'lib/red_blocks/expression.rb', line 3

def label
  @label
end

#scoreObject

Returns the value of attribute score.



3
4
5
# File 'lib/red_blocks/expression.rb', line 3

def score
  @score
end

#weightObject

Returns the value of attribute weight.



3
4
5
# File 'lib/red_blocks/expression.rb', line 3

def weight
  @weight
end

Instance Method Details

#to_sObject



16
17
18
19
# File 'lib/red_blocks/expression.rb', line 16

def to_s
  socre_str = score ? '%0.4f' % (score * weight) : '?'
  "#{socre_str}[#{label}]"
end