Class: MySQL::Search::Utils::Formatter
- Inherits:
-
Object
- Object
- MySQL::Search::Utils::Formatter
- Defined in:
- lib/mysql/search/utils/formatter.rb
Overview
Formats values for search indexing.
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(value, formatter) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(value, formatter) ⇒ Formatter
Returns a new instance of Formatter.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mysql/search/utils/formatter.rb', line 16 def initialize(value, formatter) if formatter.instance_of?(Proc) @value = formatter.call(value) @formatter = nil elsif respond_to?(formatter, true) @value = value @formatter = formatter else raise(ArgumentError, "Unknown formatter name: '#{formatter.inspect}'") end end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
8 9 10 |
# File 'lib/mysql/search/utils/formatter.rb', line 8 def formatter @formatter end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/mysql/search/utils/formatter.rb', line 8 def value @value end |
Class Method Details
.register(name, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/mysql/search/utils/formatter.rb', line 10 def self.register(name, &block) define_method(name) do block.call(value) end end |
Instance Method Details
#format ⇒ Object
28 29 30 |
# File 'lib/mysql/search/utils/formatter.rb', line 28 def format (formatter ? send(formatter) : value).to_s.strip end |