Class: XTF::Search::Element::Base
- Inherits:
-
Object
- Object
- XTF::Search::Element::Base
- Defined in:
- lib/xtf/search/element/base.rb
Constant Summary collapse
- BASE_ATTRIBUTE_KEYS =
[:field, :max_snippets, :boost]
Instance Attribute Summary collapse
-
#tag_name ⇒ Object
readonly
Returns the value of attribute tag_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns a
Hashof the attributes listed inATTRIBUTE_KEYSwith their values. -
#initialize(*args) ⇒ Base
constructor
Takes a
Hashof attributes and sets them.
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_name ⇒ Object (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
#attributes ⇒ Object
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 |