Class: MarcBot::FieldBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/marc_bot/field_builder.rb

Constant Summary collapse

SKIP_KEYS =
%i[
  indicator1
  indicator2
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, input, options) ⇒ FieldBuilder

Returns a new instance of FieldBuilder.



14
15
16
17
# File 'lib/marc_bot/field_builder.rb', line 14

def initialize(method, input, options)
  @method = method
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



12
13
14
# File 'lib/marc_bot/field_builder.rb', line 12

def input
  @input
end

#methodObject (readonly)

Returns the value of attribute method.



12
13
14
# File 'lib/marc_bot/field_builder.rb', line 12

def method
  @method
end

Class Method Details

.call(**args) ⇒ Object



8
9
10
# File 'lib/marc_bot/field_builder.rb', line 8

def self.call(**args)
  new(args.delete(:method), args.delete(:input), args).fields
end

Instance Method Details

#fieldsMARC::ControlField, MARC::DataField

Returns:

  • (MARC::ControlField, MARC::DataField)


20
21
22
23
24
25
26
27
28
# File 'lib/marc_bot/field_builder.rb', line 20

def fields
  if input.is_a?(String)
    data_or_control_field(input)
  elsif input.is_a?(Hash)
    MARC::DataField.new(tag, indicator1, indicator2, *subfield_array)
  else
    raise ArgumentError, "#{input.class} isn't a supported factory type"
  end
end