Class: JGrouper::ExportFileEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/jgrouper/export_file_entry.rb

Overview

JGrouper::ExportFileEntry - Entry from JGrouper::Exporter file

USAGE

require 'jgrouper'
require 'jgrouper/export_file_entry'
require 'jgrouper/export_file_reader'

JGrouper::ExportFileReader.new(file_name) do |reader|
  reader.next { |json| entry = JGrouper::ExportFileEntry.new json }
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json = {}) ⇒ ExportFileEntry



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/jgrouper/export_file_entry.rb', line 22

def initialize( json = {} )
  @json = json
  @kind = @json['kind']

  @key     = nil
  @name    = nil
  @stem    = nil
  @subject = nil
  @uuid    = nil # Or equivalent ...

  case @kind
  when 'admins', 'members', 'optins', 'optouts', 'readers', 'viewers', 'updaters'
    @group   = @json['group']
    @subject = @json['subject']
    @key     = [ @kind, @group['uuid'], @subject ]
  when 'composite'
    @group = @json['group']
    @key   = [ @kind, @group['uuid'] ]
  when 'creators', 'stemmers'
    @stem    = @json['stem']
    @subject = @json['subject']
    @key     = [ @kind, @stem['uuid'], @subject ]
  when 'field'
    @name = @json['name']
    @uuid = @json['uuid']
    @key  = [ @kind, @uuid ]
  when 'group'
    %w( create_subject create_time modify_subject modify_time ).each { |_| @json.delete _ }
    @name = @json['name']
    @uuid = @json['uuid']
    @key  = [ @kind, @uuid ]
  when 'group_attributes'
    @group = @json['group']
    @name  = @json['name']
    @key   = [ @kind, @group['uuid'], @name ]
  when 'group_type'
    @name = @json['name']
    @uuid = @json['uuid'] 
    @key  = [ @kind, @uuid ]
  when 'metadata'
    @key = @kind
  when 'source'
    @name = @json['name']
    @uuid = @json['id'] # Effectively ...
    @key  = [ @kind, @uuid ]
  when 'stem'
    %w( create_subject create_time modify_subject modify_time ).each { |_| @json.delete _ }
    @name = @json['name']
    @uuid = @json['uuid']
    @key  = [ @kind, @uuid ]
  else
    warn "invalid entry type: #{ @kind } - #{ @json.inspect }" unless @json.empty?
  end
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



20
21
22
# File 'lib/jgrouper/export_file_entry.rb', line 20

def json
  @json
end

#keyObject (readonly)

Returns the value of attribute key.



20
21
22
# File 'lib/jgrouper/export_file_entry.rb', line 20

def key
  @key
end

#kindObject (readonly)

Returns the value of attribute kind.



20
21
22
# File 'lib/jgrouper/export_file_entry.rb', line 20

def kind
  @kind
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



77
78
79
# File 'lib/jgrouper/export_file_entry.rb', line 77

def ==(other)
  self.class == other.class && self.kind == other.kind && self.key == other.key
end

#diff(other) ⇒ Object



83
84
85
# File 'lib/jgrouper/export_file_entry.rb', line 83

def diff(other)
  JGrouper::ExportFileDiff.new self, other
end

#hashObject



87
88
89
90
# File 'lib/jgrouper/export_file_entry.rb', line 87

def hash
  raise "nil @key - #{ @self.inspect }" if @key.nil?
  @key.hash
end

#metadata?Boolean



92
93
94
# File 'lib/jgrouper/export_file_entry.rb', line 92

def metadata?
  'metadata' == @kind
end