Class: LooseTightDictionary::Wrapper
- Inherits:
-
Object
- Object
- LooseTightDictionary::Wrapper
- Defined in:
- lib/loose_tight_dictionary/wrapper.rb
Overview
Wrappers are the tokens that are passed around when doing scoring and optimizing.
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
:nodoc: all.
-
#read ⇒ Object
readonly
Returns the value of attribute read.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(parent, record, read = nil) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #inspect ⇒ Object
- #similarity(other) ⇒ Object
- #to_str ⇒ Object (also: #to_s)
- #variants ⇒ Object
Constructor Details
#initialize(parent, record, read = nil) ⇒ Wrapper
Returns a new instance of Wrapper.
8 9 10 11 12 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 8 def initialize(parent, record, read = nil) @parent = parent @record = record @read = read end |
Instance Attribute Details
#parent ⇒ Object (readonly)
:nodoc: all
4 5 6 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 4 def parent @parent end |
#read ⇒ Object (readonly)
Returns the value of attribute read.
6 7 8 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 6 def read @read end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
5 6 7 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 5 def record @record end |
Instance Method Details
#inspect ⇒ Object
14 15 16 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 14 def inspect "#<Wrapper to_str=#{to_str} variants=#{variants.length}>" end |
#similarity(other) ⇒ Object
37 38 39 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 37 def similarity(other) Similarity.new self, other end |
#to_str ⇒ Object Also known as: to_s
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 18 def to_str @to_str ||= case read when ::Proc read.call record when ::Symbol if record.respond_to?(read) record.send read else record[read] end when ::NilClass record else record[read] end.to_s end |
#variants ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/loose_tight_dictionary/wrapper.rb', line 41 def variants @variants ||= parent.tighteners.inject([ to_str ]) do |memo, tightener| if tightener.apply? to_str memo.push tightener.apply(to_str) end memo end.uniq end |