Class: Hyrax::VisibilityIntention

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/visibility_intention.rb

Overview

Provides tools for interpreting form input as a visibility.

Since:

  • 3.0.0

Constant Summary collapse

PUBLIC =

Since:

  • 3.0.0

Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
PRIVATE =

Since:

  • 3.0.0

Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
LEASE_REQUEST =

Since:

  • 3.0.0

Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE
EMBARGO_REQUEST =

Since:

  • 3.0.0

Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(visibility: PRIVATE, release_date: nil, during: nil, after: nil) ⇒ VisibilityIntention

Returns a new instance of VisibilityIntention.

Parameters:

  • after (String) (defaults to: nil)
  • during (String) (defaults to: nil)
  • release_date (String) (defaults to: nil)
  • visibility (String) (defaults to: PRIVATE)

Since:

  • 3.0.0


29
30
31
32
33
34
# File 'app/services/hyrax/visibility_intention.rb', line 29

def initialize(visibility: PRIVATE, release_date: nil, during: nil, after: nil)
  self.after        = after
  self.during       = during
  self.release_date = release_date
  self.visibility   = visibility
end

Instance Attribute Details

#afterString

Returns the visibility requested after the embargo/lease release.

Returns:

  • (String)

    the visibility requested after the embargo/lease release


22
23
24
# File 'app/services/hyrax/visibility_intention.rb', line 22

def after
  @after
end

#duringString

Returns the visibility requested while the embargo/lease is in effect.

Returns:

  • (String)

    the visibility requested while the embargo/lease is in effect


22
# File 'app/services/hyrax/visibility_intention.rb', line 22

attr_accessor :after, :during, :release_date, :visibility

#release_dateString

Returns:

  • (String)

22
# File 'app/services/hyrax/visibility_intention.rb', line 22

attr_accessor :after, :during, :release_date, :visibility

#visibilityString

Returns:

  • (String)

22
# File 'app/services/hyrax/visibility_intention.rb', line 22

attr_accessor :after, :during, :release_date, :visibility

Instance Method Details

#embargo_paramsArray

Returns the parameters for the requested embargo.

Returns:

  • (Array)

    the parameters for the requested embargo

Raises:

  • (ArgumentError)

Since:

  • 3.0.0


38
39
40
41
42
43
# File 'app/services/hyrax/visibility_intention.rb', line 38

def embargo_params
  return []           unless wants_embargo?
  raise ArgumentError unless valid_embargo?

  [release_date, (during || PRIVATE), (after || PUBLIC)]
end

#lease_paramsArray

Returns the parameters for the requested embargo.

Returns:

  • (Array)

    the parameters for the requested embargo

Raises:

  • (ArgumentError)

Since:

  • 3.0.0


47
48
49
50
51
52
# File 'app/services/hyrax/visibility_intention.rb', line 47

def lease_params
  return []           unless wants_lease?
  raise ArgumentError unless valid_lease?

  [release_date, (during || PUBLIC), (after || PRIVATE)]
end

#valid_embargo?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0


56
57
58
# File 'app/services/hyrax/visibility_intention.rb', line 56

def valid_embargo?
  wants_embargo? && release_date.present? && a_valid_date?(release_date)
end

#valid_lease?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0


68
69
70
# File 'app/services/hyrax/visibility_intention.rb', line 68

def valid_lease?
  wants_lease? && release_date.present? && a_valid_date?(release_date)
end

#wants_embargo?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0


62
63
64
# File 'app/services/hyrax/visibility_intention.rb', line 62

def wants_embargo?
  visibility == EMBARGO_REQUEST
end

#wants_lease?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0


74
75
76
# File 'app/services/hyrax/visibility_intention.rb', line 74

def wants_lease?
  visibility == LEASE_REQUEST
end