Class: MARCSpec::ConstantSolrSpec
- Inherits:
-
SolrFieldSpec
- Object
- SolrFieldSpec
- MARCSpec::ConstantSolrSpec
- Defined in:
- lib/marcspec/constantspec.rb,
lib/marcspec/dsl.rb
Overview
A ConstantSolrSpec always returns the same value(s) no matter what's in the record.
Instance Attribute Summary collapse
-
#constantValue ⇒ Object
Returns the value of attribute constantValue.
Attributes inherited from SolrFieldSpec
#_mapname, #arity, #defaultValue, #first, #map, #marcfieldspecs, #noMapKeyDefault, #solrField
Class Method Summary collapse
-
.fromHash(h) ⇒ Object
deprecated
Deprecated.
Use the DSL
Instance Method Summary collapse
-
#==(other) ⇒ Object
Basic equality.
- #asDSLString ⇒ Object
-
#asPPString ⇒ Object
deprecated
Deprecated.
Use the DSL
-
#initialize(opts = {}) ⇒ ConstantSolrSpec
constructor
A new instance of ConstantSolrSpec.
-
#marc_values(r, doc = {}) ⇒ String, Array
Return the constant value associated with this spec.
- #value(val) ⇒ Object
Methods inherited from SolrFieldSpec
#<<, #default, #firstOnly, fromPPString, #mapMissDefault, #mapname, #pretty_print, #raw_marc_values, #spec
Constructor Details
#initialize(opts = {}) ⇒ ConstantSolrSpec
Returns a new instance of ConstantSolrSpec.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/marcspec/constantspec.rb', line 11 def initialize opts = {} @solrField = opts[:solrField] @constantValue = opts[:constantValue] @arity = 1 # Check to make sure we didn't get anything else and warn if need be [:firstOnly, :mapname, :noMapKeyDefault, :specs, :default, :module, :functionSymbol].each do |s| if opts[s] raise ArgumentError, "#{s} is not a valid option for Constant spec (one with :constantValue defined)" end end end |
Instance Attribute Details
#constantValue ⇒ Object
Returns the value of attribute constantValue.
8 9 10 |
# File 'lib/marcspec/constantspec.rb', line 8 def constantValue @constantValue end |
Class Method Details
.fromHash(h) ⇒ Object
Deprecated.
Use the DSL
Build up from a ruby hash
40 41 42 |
# File 'lib/marcspec/constantspec.rb', line 40 def self.fromHash h return self.new(h) end |
Instance Method Details
#==(other) ⇒ Object
Basic equality
34 35 36 |
# File 'lib/marcspec/constantspec.rb', line 34 def == other return @constantValue == other.constantValue end |
#asDSLString ⇒ Object
44 45 46 |
# File 'lib/marcspec/constantspec.rb', line 44 def asDSLString return "constant('#{@solrField}') do\n value #{@constantValue.inspect}\nend" end |
#asPPString ⇒ Object
Deprecated.
Use the DSL
Used to round-trip to/from hash syntax
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/marcspec/constantspec.rb', line 50 def asPPString s = StringIO.new s.print "{\n :solrField=> " PP.singleline_pp(@solrField, s) s.print(",\n ") s.print ":constantValue => " PP.singleline_pp(@constantValue, s) s.print "\n}" return s.string end |
#marc_values(r, doc = {}) ⇒ String, Array
Return the constant value associated with this spec
29 30 31 |
# File 'lib/marcspec/constantspec.rb', line 29 def marc_values r, doc = {} return @constantValue end |
#value(val) ⇒ Object
167 168 169 |
# File 'lib/marcspec/dsl.rb', line 167 def value(val) self.constantValue = val end |