Class: CFF::ModelPart

Inherits:
Object
  • Object
show all
Defined in:
lib/cff/model_part.rb

Overview

ModelPart is the superclass of anything that makes up part of the CFF Index. This includes Index, Person, Entity and Reference.

ModelPart provides only one method for the public API: empty?.

Direct Known Subclasses

Entity, Identifier, Index, Person, Reference

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/cff/model_part.rb', line 29

def method_missing(name, *args)
  n = method_to_field(name.id2name)
  super unless self.class::ALLOWED_FIELDS.include?(n.chomp('='))

  if n.end_with?('=')
    @fields[n.chomp('=')] = args[0] || ''
  else
    @fields[n].nil? ? '' : @fields[n]
  end
end

Instance Attribute Details

#fieldsObject (readonly)

:stopdoc:



27
28
29
# File 'lib/cff/model_part.rb', line 27

def fields
  @fields
end

Class Method Details

.attr_date(*symbols) ⇒ Object

:nodoc:



58
59
60
61
62
63
64
65
# File 'lib/cff/model_part.rb', line 58

def self.attr_date(*symbols) # :nodoc:
  symbols.each do |symbol|
    field = symbol.to_s.tr('_', '-')

    date_getter(symbol, field)
    date_setter(symbol, field)
  end
end

Instance Method Details

#empty?Boolean

:call-seq:

empty? -> false

Define empty? for CFF classes so that they can be tested in the same way as strings and arrays.

This always returns false because CFF classes always return something from all of their methods.

Returns:

  • (Boolean)


54
55
56
# File 'lib/cff/model_part.rb', line 54

def empty?
  false
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/cff/model_part.rb', line 40

def respond_to_missing?(name, *)
  n = method_to_field(name.id2name)
  self.class::ALLOWED_FIELDS.include?(n.chomp('=')) || super
end