Class: JGrouper::Exporter
- Inherits:
-
Object
- Object
- JGrouper::Exporter
- Defined in:
- lib/jgrouper/exporter.rb
Overview
JGrouper::Exporter - Export (some of the) Groups registry to CSV
USAGE
require 'jgrouper'
require 'jgrouper/exporter'
JGrouper::Exporter do |exporter|
exporter.export 'stem:to:export'
end
Instance Attribute Summary collapse
-
#verbose ⇒ Object
writeonly
Sets the attribute verbose.
Instance Method Summary collapse
-
#export(base = nil) ⇒ Object
Export (some of the) Groups registry to CSV.
-
#initialize {|_self| ... } ⇒ Exporter
constructor
A new instance of Exporter.
Constructor Details
#initialize {|_self| ... } ⇒ Exporter
Returns a new instance of Exporter.
20 21 22 23 24 25 26 |
# File 'lib/jgrouper/exporter.rb', line 20 def initialize @directory = Dir.pwd @fh = nil @verbose = false yield self if block_given? self end |
Instance Attribute Details
#verbose=(value) ⇒ Object (writeonly)
Sets the attribute verbose
18 19 20 |
# File 'lib/jgrouper/exporter.rb', line 18 def verbose=(value) @verbose = value end |
Instance Method Details
#export(base = nil) ⇒ Object
Export (some of the) Groups registry to CSV.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jgrouper/exporter.rb', line 31 def export( base = nil ) entries = [] filehandle @directory, "jgrouper-export.csv" do stem = base.nil? ? Stem.root : Stem.find(base) raise "ERROR: stem not found" if stem.nil? log "exporting stem=#{stem.name} ..." raise "NOT IMPLEMENTED - exporting child stems" if stem.stems.size > 0 groups = stem.groups do |child| g = %w( display_extension extension name ).collect { |k| child.send(k) } g << CSV.generate_line( child.members.collect { |m| "#{ m.subject_source_id }|#{ m.subject_type_id }|#{ m.subject_id }" } ).chomp entries << CSV.generate_line(g) @fh.puts entries.last yield entries.last if block_given? end log "exporting stem=#{stem.name} - done" end entries end |