Module: Parliament::Grom::Decorator::Question

Includes:
Helpers::DateHelper
Defined in:
lib/parliament/grom/decorator/question.rb

Overview

Decorator namespace for Grom::Node instances with type: id.parliament.uk/schema/Question.

Since:

  • 0.1.0

Instance Method Summary collapse

Methods included from Helpers::DateHelper

#date_range

Instance Method Details

#answering_body_allocationGrom::Node?

Alias questionHasAnsweringBodyAllocation with fallback.

Returns:

  • (Grom::Node, nil)

    the answering_body_allocation of the Grom::Node or nil.

Since:

  • 0.1.0



66
67
68
# File 'lib/parliament/grom/decorator/question.rb', line 66

def answering_body_allocation
  respond_to?(:questionHasAnsweringBodyAllocation) ? questionHasAnsweringBodyAllocation.first : nil
end

#answersArray

Alias questionHasAnswer with fallback.

Returns:

  • (Array, Array)

    the answers related to the Grom::Node or an empty array.

Since:

  • 0.1.0



59
60
61
# File 'lib/parliament/grom/decorator/question.rb', line 59

def answers
  respond_to?(:questionHasAnswer) ? questionHasAnswer : []
end

#asked_at_dateDateTime?

Alias questionAskedAt with fallback.

Returns:

  • (DateTime, nil)

    the asked_at_date of the Grom::Node or nil.

Since:

  • 0.1.0



45
46
47
# File 'lib/parliament/grom/decorator/question.rb', line 45

def asked_at_date
  @asked_at_date ||= respond_to?(:questionAskedAt) ? DateTime.parse(questionAskedAt) : nil
end

#asking_personGrom::Node?

Alias questionHasAskingPerson with fallback.

Returns:

  • (Grom::Node, nil)

    the asking_person of the Grom::Node or nil.

Since:

  • 0.1.0



52
53
54
# File 'lib/parliament/grom/decorator/question.rb', line 52

def asking_person
  respond_to?(:questionHasAskingPerson) ? questionHasAskingPerson.first : nil
end

#fallback_headingString

Builds a fallback question heading using indexingAndSearchUri.

Returns:

  • (String, String)

    the fallback_heading of the Grom::Node.

Since:

  • 0.1.0



17
18
19
# File 'lib/parliament/grom/decorator/question.rb', line 17

def fallback_heading
  "Question #{indexing_search_uri.split('/').last}"
end

#headingString

Returns heading or fallback_heading.

Returns:

  • (String, String)

    the heading of the Grom::Node or fallback_heading.

Since:

  • 0.1.0



24
25
26
# File 'lib/parliament/grom/decorator/question.rb', line 24

def heading
  question_title.empty? || question_title.include?('Tabled Parliamentary Question') ? fallback_heading : question_title
end

#indexing_search_uriString

Alias indexingAndSearchUri with fallback.

Returns:

  • (String, String)

    the indexing_search_uri of the Grom::Node or an empty string.

Since:

  • 0.1.0



38
39
40
# File 'lib/parliament/grom/decorator/question.rb', line 38

def indexing_search_uri
  respond_to?(:indexingAndSearchUri) ? indexingAndSearchUri : ''
end

#question_titleString

Alias questionHeading with fallback.

Returns:

  • (String, String)

    the question_title of the Grom::Node or an empty string.

Since:

  • 0.1.0



10
11
12
# File 'lib/parliament/grom/decorator/question.rb', line 10

def question_title
  respond_to?(:questionHeading) ? questionHeading : ''
end

#textString

Alias questionText with fallback.

Returns:

  • (String, String)

    the text of the Grom::Node or an empty string.

Since:

  • 0.1.0



31
32
33
# File 'lib/parliament/grom/decorator/question.rb', line 31

def text
  respond_to?(:questionText) ? questionText : ''
end