Class: RSolr::Field
- Inherits:
-
Object
- Object
- RSolr::Field
- Defined in:
- lib/rsolr/field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attrs ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “value” is the text value for the node.
-
#source_value ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “value” is the text value for the node.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(attrs, source_value) ⇒ Field
constructor
“attrs” must be a hash “value” should be something that responds to #_to_s.
-
#name ⇒ Object
the value of the “name” attribute.
- #value ⇒ Object
Constructor Details
#initialize(attrs, source_value) ⇒ Field
“attrs” must be a hash “value” should be something that responds to #_to_s
31 32 33 34 |
# File 'lib/rsolr/field.rb', line 31 def initialize(attrs, source_value) @attrs = attrs @source_value = source_value end |
Instance Attribute Details
#attrs ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “value” is the text value for the node
27 28 29 |
# File 'lib/rsolr/field.rb', line 27 def attrs @attrs end |
#source_value ⇒ Object
“attrs” is a hash for setting the “doc” xml attributes “value” is the text value for the node
27 28 29 |
# File 'lib/rsolr/field.rb', line 27 def source_value @source_value end |
Class Method Details
.instance(attrs, value) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rsolr/field.rb', line 3 def self.instance(attrs, value) attrs = attrs.dup field_type = attrs.delete(:type) { value.class.name } klass = if field_type.is_a? String class_for_field(field_type) elsif field_type.is_a? Class field_type else self end klass.new(attrs, value) end |
Instance Method Details
#as_json ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rsolr/field.rb', line 45 def as_json if attrs[:update] { attrs[:update] => value } elsif attrs.any? { |k, _| k != :name } hash = attrs.dup hash.delete(:name) hash.merge(value: value) else value end end |
#name ⇒ Object
the value of the “name” attribute
37 38 39 |
# File 'lib/rsolr/field.rb', line 37 def name attrs[:name] end |
#value ⇒ Object
41 42 43 |
# File 'lib/rsolr/field.rb', line 41 def value source_value end |