Class: Odca::SchemaBase

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/odca/schema_base.rb

Defined Under Namespace

Classes: Attribute, Header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header) ⇒ SchemaBase

Returns a new instance of SchemaBase.



10
11
12
13
# File 'lib/odca/schema_base.rb', line 10

def initialize(header)
  @attributes = []
  @header = header
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'lib/odca/schema_base.rb', line 6

def attributes
  @attributes
end

#headerObject (readonly)

Returns the value of attribute header.



6
7
8
# File 'lib/odca/schema_base.rb', line 6

def header
  @header
end

Instance Method Details

#add_attribute(attribute) ⇒ Object



24
25
26
# File 'lib/odca/schema_base.rb', line 24

def add_attribute(attribute)
  attributes << attribute
end

#pii_attributesObject



28
29
30
# File 'lib/odca/schema_base.rb', line 28

def pii_attributes
  attributes.select(&:pii?)
end

#to_hObject



15
16
17
18
19
20
21
22
# File 'lib/odca/schema_base.rb', line 15

def to_h
  header.to_h.merge(
    attributes: attributes.each_with_object({}) do |attr, memo|
      memo[attr.name] = attr.type
    end,
    pii_attributes: pii_attributes.map(&:name)
  )
end

#to_json(*options) ⇒ Object



32
33
34
# File 'lib/odca/schema_base.rb', line 32

def to_json(*options)
  to_h.to_json(*options)
end