Class: Hanover::GSet

Inherits:
Object
  • Object
show all
Defined in:
lib/hanover/g_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGSet

Returns a new instance of GSet.



4
5
6
# File 'lib/hanover/g_set.rb', line 4

def initialize
  self.members = Set.new
end

Instance Attribute Details

#membersObject

Returns the value of attribute members.



3
4
5
# File 'lib/hanover/g_set.rb', line 3

def members
  @members
end

Class Method Details

.from_json(json) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/hanover/g_set.rb', line 8

def self.from_json(json)
  h = JSON.parse json, symbolize_names: true
  raise ArgumentError.new 'unexpected type field in JSON' unless h[:type] == 'GSet'
  
  gs = new
  gs.members.merge h[:a]
  
  return gs
end

Instance Method Details

#add(atom) ⇒ Object



18
19
20
# File 'lib/hanover/g_set.rb', line 18

def add(atom)
  self.members.add atom
end

#include?(atom) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/hanover/g_set.rb', line 22

def include?(atom)
  self.members.include? atom
end

#merge(other) ⇒ Object



33
34
35
# File 'lib/hanover/g_set.rb', line 33

def merge(other)
  self.members.merge other.members
end

#to_json(*args) ⇒ Object



26
27
28
29
30
31
# File 'lib/hanover/g_set.rb', line 26

def to_json(*args)
  {
    type: 'GSet',
    a: self.members.to_a
    }.to_json(*args)
end