Class: SearchMagic::Metadata
- Inherits:
-
Object
- Object
- SearchMagic::Metadata
- Defined in:
- lib/search_magic/metadata.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#through ⇒ Object
Returns the value of attribute through.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #arrangeable_value_for(obj) ⇒ Object
- #comparable? ⇒ Boolean
- #datable? ⇒ Boolean
- #hashable? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #name ⇒ Object
- #search_regex_fragment ⇒ Object
- #searchable_value_for(obj) ⇒ Object
- #unnameable? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Metadata
Returns a new instance of Metadata.
5 6 7 8 9 |
# File 'lib/search_magic/metadata.rb', line 5 def initialize(attributes = {}) attributes.each do |key, value| send(:"#{key}=", value) end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/search_magic/metadata.rb', line 3 def @options end |
#through ⇒ Object
Returns the value of attribute through.
3 4 5 |
# File 'lib/search_magic/metadata.rb', line 3 def through @through end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/search_magic/metadata.rb', line 3 def type @type end |
Instance Method Details
#arrangeable_value_for(obj) ⇒ Object
35 36 37 |
# File 'lib/search_magic/metadata.rb', line 35 def arrangeable_value_for(obj) post_process(get_value(obj)) end |
#comparable? ⇒ Boolean
19 20 21 |
# File 'lib/search_magic/metadata.rb', line 19 def comparable? @comparable ||= self.type.public_instance_methods.include? :< end |
#datable? ⇒ Boolean
23 24 25 |
# File 'lib/search_magic/metadata.rb', line 23 def datable? @datable ||= [Date, DateTime, Time].include? self.type end |
#hashable? ⇒ Boolean
31 32 33 |
# File 'lib/search_magic/metadata.rb', line 31 def hashable? @hashable ||= self.type <= Hash end |
#name ⇒ Object
11 12 13 |
# File 'lib/search_magic/metadata.rb', line 11 def name @name ||= through.map(&:term).compact.join("_").to_sym end |
#search_regex_fragment ⇒ Object
15 16 17 |
# File 'lib/search_magic/metadata.rb', line 15 def search_regex_fragment self.hashable? ? "#{name}#{separator}[^#{separator}\\s]+" : name.to_s end |
#searchable_value_for(obj) ⇒ Object
39 40 41 |
# File 'lib/search_magic/metadata.rb', line 39 def searchable_value_for(obj) value_for(get_value(obj)).downcase.split.map {|word| [name.blank? ? nil : name, word].compact.join(separator)} end |
#unnameable? ⇒ Boolean
27 28 29 |
# File 'lib/search_magic/metadata.rb', line 27 def unnameable? @unnameable ||= self.name == :"" end |