Class: XTF::Search::Element::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/xtf/search/element/base.rb

Direct Known Subclasses

Clause, Facet, Query, Term

Constant Summary collapse

BASE_ATTRIBUTE_KEYS =
[:field, :max_snippets, :boost]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Takes a Hash of attributes and sets them. Silently ignores erroneous keys.



18
19
20
21
# File 'lib/xtf/search/element/base.rb', line 18

def initialize(*args)
  params = args[0]
  attribute_keys.each { |k| self.__send__("#{k}=", params[k]) if params.key?(k) } if params
end

Instance Attribute Details

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



15
16
17
# File 'lib/xtf/search/element/base.rb', line 15

def tag_name
  @tag_name
end

Class Method Details

.attribute_keys(*args) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/xtf/search/element/base.rb', line 4

def self.attribute_keys(*args)
  array = args.flatten
  list = array.inspect
  class_eval(%Q{def attribute_keys() #{list} end}, __FILE__, __LINE__)
  array.each do |k|
    attr_accessor k
  end
end

Instance Method Details

#attributesObject

Returns a Hash of the attributes listed in ATTRIBUTE_KEYS with their values. The keys are Symbols.



25
26
27
28
29
30
# File 'lib/xtf/search/element/base.rb', line 25

def attributes
  self.attribute_keys.inject({}) do |hash, key|
    hash[key] = self.__send__(key) if self.__send__(key)
    hash
  end
end