Class: SimpleSolrClient::Schema::Field_or_Type
- Inherits:
-
Object
- Object
- SimpleSolrClient::Schema::Field_or_Type
- Includes:
- Comparable
- Defined in:
- lib/simple_solr_client/schema/field_or_type.rb
Constant Summary collapse
- TEXT_ATTR_MAP =
{ :name => 'name', :type_name => 'type', :precision_step => 'precisionStep', :position_increment_gap => 'positionIncrementGap' }
- BOOL_ATTR_MAP =
{ :stored => 'stored', :indexed => 'indexed', :multi => 'multiValued', :multivalued => 'multiValued', :multiValued => 'multiValued', :multi_valued => 'multiValued', :sort_missing_last => 'sortMissingLast', :docvalues => 'docValues', :docValues => 'docvalues', :doc_values => 'docvalues', }
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type_name ⇒ Object
Returns the value of attribute type_name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](k) ⇒ Object
Allow access to methods via [], for easy looping.
- #[]=(k, v) ⇒ Object
-
#initialize(h = {}) ⇒ Field_or_Type
constructor
Take in a hash, and set anything in it that we recognize.
-
#to_h ⇒ Object
Make a hash out of it, for easy feeding back into another call to #new.
- #to_xml ⇒ Object
-
#to_xml_node ⇒ Object
Reverse the process to get XML.
Constructor Details
#initialize(h = {}) ⇒ Field_or_Type
Take in a hash, and set anything in it that we recognize. Sloppy from a data point of view, but make for easy duplication and creation from xml/json
15 16 17 18 19 20 21 22 23 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 15 def initialize(h = {}) @attributes = {} h.each_pair do |k, v| begin self[k] = v rescue end end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 7 def name @name end |
#type_name ⇒ Object
Returns the value of attribute type_name.
7 8 9 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 7 def type_name @type_name end |
Class Method Details
.new_from_solr_hash(h) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 57 def self.new_from_solr_hash(h) f = self.new TEXT_ATTR_MAP.merge(BOOL_ATTR_MAP).each_pair do |field, xmlattr| define_method(field.to_sym) do self[field.to_sym] end f[field] = h[xmlattr] end # Make some "method?" for the boolean attributes BOOL_ATTR_MAP.keys.each do |methname| q_methname = ((methname.to_s) + '?').to_sym alias_method q_methname, methname end # Set the name "manually" to force the # matcher f.name = h['name'] f end |
Instance Method Details
#==(other) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 48 def ==(other) if other.respond_to? :name name == other.name and type_name == other.type_name else name == other end end |
#[](k) ⇒ Object
Allow access to methods via [], for easy looping
96 97 98 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 96 def [](k) @attributes[k.to_sym] end |
#[]=(k, v) ⇒ Object
100 101 102 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 100 def []=(k, v) @attributes[k.to_sym] = v end |
#to_h ⇒ Object
Make a hash out of it, for easy feeding back into another call to #new
106 107 108 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 106 def to_h @attributes end |
#to_xml ⇒ Object
91 92 93 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 91 def to_xml to_xml_node.to_xml end |
#to_xml_node ⇒ Object
Reverse the process to get XML
81 82 83 84 85 86 87 88 89 |
# File 'lib/simple_solr_client/schema/field_or_type.rb', line 81 def to_xml_node doc ||= Nokogiri::XML::Document.new xml = xml_node(doc) TEXT_ATTR_MAP.merge(BOOL_ATTR_MAP).each_pair do |field, xmlattr| iv = instance_variable_get("@#{field}".to_sym) xml[xmlattr] = iv unless iv.nil? end xml end |