Class: SearchMagic::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/search_magic/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/search_magic/metadata.rb', line 3

def options
  @options
end

#throughObject

Returns the value of attribute through.



3
4
5
# File 'lib/search_magic/metadata.rb', line 3

def through
  @through
end

#typeObject

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

Returns:

  • (Boolean)


19
20
21
# File 'lib/search_magic/metadata.rb', line 19

def comparable?
  @comparable ||= self.type.public_instance_methods.include? :<
end

#datable?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/search_magic/metadata.rb', line 23

def datable?
  @datable ||= [Date, DateTime, Time].include? self.type
end

#hashable?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/search_magic/metadata.rb', line 31

def hashable?
  @hashable ||= self.type <= Hash
end

#nameObject



11
12
13
# File 'lib/search_magic/metadata.rb', line 11

def name
  @name ||= through.map(&:term).compact.join("_").to_sym
end

#search_regex_fragmentObject



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/search_magic/metadata.rb', line 27

def unnameable?
  @unnameable ||= self.name == :""
end