Class: ARWrapperModel

Inherits:
OAI::Provider::Model
  • Object
show all
Defined in:
lib/ar_wrapper_model.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ARWrapperModel

Returns a new instance of ARWrapperModel.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ar_wrapper_model.rb', line 4

def initialize(options={})
  @timestamp_field = options.delete(:timestamp_field) || 'updated_at'
  @limit = options.delete(:limit)
  @models = options.delete(:models)
  @sets_map = options.delete(:sets) || []
  @oai_dc_mapping = {}

  if @models.nil? or @models.empty?
    raise "models configuration value is required and must be non-empty"
  end

  unless options.empty?
    raise ArgumentError.new(
      "Unsupported options [#{options.keys.join(', ')}]"
    )
  end

end

Instance Method Details

#earliestObject



45
46
47
# File 'lib/ar_wrapper_model.rb', line 45

def earliest
  first_record_date(:asc)
end

#find(selector, options = {}) ⇒ Object

selector can be id or :all



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ar_wrapper_model.rb', line 54

def find(selector, options={})
  token = nil
  if options[:resumption_token]
    raise OAI::ResumptionTokenException.new unless @limit
    token = ResumptionToken.parse(options[:resumption_token])
  end

  from   = token ? token.from.utc  : options[:from]
  to     = token ? token.until.utc : options[:until]
  last   = token ? token.last   : 0
  set    = token ? token.set    : options[:set]
  prefix = token ? token.prefix : options[:metadata_prefix]

  record_rows = get_record_rows(set, :from => from, :until => to)

  return get_specific_record(record_rows, selector) if selector != :all

  if @limit and record_rows.size > @limit
    get_paged_records(record_rows, :from => from, :until => to, :set => set, :last => last, :metadata_prefix => prefix)
  else
    get_record_objects(record_rows)
  end
end

#latestObject



49
50
51
# File 'lib/ar_wrapper_model.rb', line 49

def latest
  first_record_date(:desc)
end

#map_oai_dcObject



23
24
25
26
27
28
29
30
31
# File 'lib/ar_wrapper_model.rb', line 23

def map_oai_dc
  if @oai_dc_mapping.empty?
    dc = OAI::Provider::Metadata::DublinCore.instance
    dc.fields.map do |field|
      @oai_dc_mapping[field.to_sym] = "oai_dc_#{field}".to_sym
    end
  end
  @oai_dc_mapping
end

#setsObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ar_wrapper_model.rb', line 33

def sets
  @sets_map.map {|set_obj|
    OAI::Set.new(
      {
        name: set_obj[:name],
        spec: set_obj[:spec],
        description: set_obj[:description]
      }
    )
  }
end