Class: ARWrapperModel
- Inherits:
-
OAI::Provider::Model
- Object
- OAI::Provider::Model
- ARWrapperModel
- Defined in:
- lib/ar_wrapper_model.rb
Instance Method Summary collapse
- #earliest ⇒ Object
-
#find(selector, options = {}) ⇒ Object
selector can be id or :all.
-
#initialize(options = {}) ⇒ ARWrapperModel
constructor
A new instance of ARWrapperModel.
- #latest ⇒ Object
- #map_oai_dc ⇒ Object
- #sets ⇒ Object
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(={}) @timestamp_field = .delete(:timestamp_field) || 'updated_at' @limit = .delete(:limit) @models = .delete(:models) @sets_map = .delete(:sets) || [] @oai_dc_mapping = {} if @models.nil? or @models.empty? raise "models configuration value is required and must be non-empty" end unless .empty? raise ArgumentError.new( "Unsupported options [#{.keys.join(', ')}]" ) end end |
Instance Method Details
#earliest ⇒ Object
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, ={}) token = nil if [:resumption_token] raise OAI::ResumptionTokenException.new unless @limit token = ResumptionToken.parse([:resumption_token]) end from = token ? token.from.utc : [:from] to = token ? token.until.utc : [:until] last = token ? token.last : 0 set = token ? token.set : [:set] prefix = token ? token.prefix : [: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 |
#latest ⇒ Object
49 50 51 |
# File 'lib/ar_wrapper_model.rb', line 49 def latest first_record_date(:desc) end |
#map_oai_dc ⇒ Object
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 |
#sets ⇒ Object
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 |