Class: ThinkingSphinx::Facet
- Inherits:
-
Object
- Object
- ThinkingSphinx::Facet
- Defined in:
- lib/thinking_sphinx/facet.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#reference ⇒ Object
readonly
Returns the value of attribute reference.
Class Method Summary collapse
Instance Method Summary collapse
- #attribute_name ⇒ Object
-
#initialize(reference) ⇒ Facet
constructor
A new instance of Facet.
- #name ⇒ Object
- #to_s ⇒ Object
- #value(object, attribute_value) ⇒ Object
Constructor Details
#initialize(reference) ⇒ Facet
Returns a new instance of Facet.
5 6 7 8 9 10 11 |
# File 'lib/thinking_sphinx/facet.rb', line 5 def initialize(reference) @reference = reference if reference.columns.length != 1 raise "Can't translate Facets on multiple-column field or attribute" end end |
Instance Attribute Details
#reference ⇒ Object (readonly)
Returns the value of attribute reference.
3 4 5 |
# File 'lib/thinking_sphinx/facet.rb', line 3 def reference @reference end |
Class Method Details
.attribute_name_for(name) ⇒ Object
26 27 28 |
# File 'lib/thinking_sphinx/facet.rb', line 26 def self.attribute_name_for(name) name.to_s == 'class' ? 'class_crc' : "#{name}_facet" end |
.name_for(facet) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/thinking_sphinx/facet.rb', line 13 def self.name_for(facet) case facet when Facet facet.name when String, Symbol facet.to_s.gsub(/(_facet|_crc)$/,'').to_sym end end |
Instance Method Details
#attribute_name ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/thinking_sphinx/facet.rb', line 30 def attribute_name # @attribute_name ||= case @reference # when Attribute # @reference.unique_name.to_s # when Field @attribute_name ||= @reference.unique_name.to_s + "_facet" # end end |
#name ⇒ Object
22 23 24 |
# File 'lib/thinking_sphinx/facet.rb', line 22 def name reference.unique_name end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/thinking_sphinx/facet.rb', line 54 def to_s name end |
#value(object, attribute_value) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/thinking_sphinx/facet.rb', line 39 def value(object, attribute_value) return translate(object, attribute_value) if @reference.is_a?(Field) case @reference.type when :string translate(object, attribute_value) when :datetime Time.at(attribute_value) when :boolean attribute_value > 0 else attribute_value end end |