Class: Accessor::DomesticRecommendationsAccessor

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/accessor/domestic_recommendations_accessor.rb

Defined Under Namespace

Classes: RecommendationDetails

Instance Method Summary collapse

Instance Method Details

#fetch_details(schema_version:, improvement_number:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/accessor/domestic_recommendations_accessor.rb', line 9

def fetch_details(schema_version:, improvement_number:)
  unless memoized_schema?(schema_version)
    assessment_type = schema_version.split("-").first
    is_ni = schema_version.include? "-NI-"
    definitions_document = Nokogiri::XML(File.open("api/schemas/xml/#{schema_version}/#{assessment_type}/ExternalDefinitions.xml"))
    sub_object = {}
    country_node = definitions_document.at_xpath("//Country[Country-Code[contains(text(), '#{is_ni ? 'NIR' : 'EAW'}')]]")
    recommendations = country_node.search("Recommendation")
    recommendations.each do |recommendation|
      sub_object[recommendation.at_css("Improvement-Number").content] = {
        summary: recommendation.at_css("Improvement-Summary[language='1']").content,
        description: recommendation.at_css("Improvement-Description[language='1']").content,
      }
    end
    memoize_schema_hash(schema_version, sub_object)
  end
  RecommendationDetails.new(**memoized_schema(schema_version)[improvement_number])
end

#reset!Object



28
29
30
# File 'lib/accessor/domestic_recommendations_accessor.rb', line 28

def reset!
  @memo = nil
end