Class: YaPPL::Rule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Rule

Returns a new instance of Rule.



7
8
9
10
11
12
13
# File 'lib/rule.rb', line 7

def initialize(args = {})
  args.each do |key, value|
    self.instance_variable_set("@#{key}".to_sym, value)
  end
  @valid_from = Time.now unless valid_from
  @expiration_date = default_time unless expiration_date
end

Instance Attribute Details

#excluded_purposesObject (readonly)

Returns the value of attribute excluded_purposes.



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

def excluded_purposes
  @excluded_purposes
end

#excluded_utilizersObject (readonly)

Returns the value of attribute excluded_utilizers.



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

def excluded_utilizers
  @excluded_utilizers
end

#expiration_dateObject (readonly)

Returns the value of attribute expiration_date.



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

def expiration_date
  @expiration_date
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#permitted_purposesObject (readonly)

Returns the value of attribute permitted_purposes.



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

def permitted_purposes
  @permitted_purposes
end

#permitted_utilizersObject (readonly)

Returns the value of attribute permitted_utilizers.



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

def permitted_utilizers
  @permitted_utilizers
end

#transformationsObject (readonly)

Returns the value of attribute transformations.



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

def transformations
  @transformations
end

#valid_fromObject (readonly)

Returns the value of attribute valid_from.



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

def valid_from
  @valid_from
end

Instance Method Details

#archive!Object



15
16
17
18
# File 'lib/rule.rb', line 15

def archive!
  @id = -1
  @expiration_date = Time.now
end

#expired?Boolean

Returns:

  • (Boolean)


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

def expired?
  expiration_date != default_time && Time.now > expiration_date
end

#to_hObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rule.rb', line 24

def to_h
  {
    purpose: {
      permitted: permitted_purposes,
      excluded: excluded_purposes
    },
    utilizer: {
      permitted: permitted_utilizers,
      excluded: excluded_utilizers
    },
    transformation: transformations,
    valid_from: valid_from.strftime('%FT%T.%LZ'),
    exp_date: expiration_date.strftime('%FT%T.%LZ')
  }
end