Class: MARCSpec::ConstantSolrSpec

Inherits:
SolrFieldSpec show all
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

Attributes inherited from SolrFieldSpec

#_mapname, #arity, #defaultValue, #first, #map, #marcfieldspecs, #noMapKeyDefault, #solrField

Class Method Summary collapse

Instance Method Summary collapse

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

#constantValueObject

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

#asDSLStringObject



44
45
46
# File 'lib/marcspec/constantspec.rb', line 44

def asDSLString
  return "constant('#{@solrField}') do\n  value #{@constantValue.inspect}\nend"
end

#asPPStringObject

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

Parameters:

  • r (MARC4J4R::Record)

    The record. IGNORED. It’s a constant ;-)

  • doc (Hash, SolrInputDocument) (defaults to: {})

    The hash-like object that contains previously-generated content. IGNORED

Returns:

  • (String, Array)

    The constant value(s) associated with this object.



29
30
31
# File 'lib/marcspec/constantspec.rb', line 29

def marc_values r, doc = {}
  return @constantValue
end

#value(val) ⇒ Object



161
162
163
# File 'lib/marcspec/dsl.rb', line 161

def value(val)
  self.constantValue = val
end