Class: TaxGenerator::Destination

Inherits:
Object
  • Object
show all
Includes:
ApplicationHelper
Defined in:
lib/tax_generator/classes/destination.rb

Overview

class used to find xpaths from the destination node from xml

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

create_directories, elements_with_content, erb_template, execute_with_rescue, format_error, log_error, log_message, nokogiri_xml, rescue_interrupt, root

Constructor Details

#initialize(destination_node) ⇒ void

receives destination node (xml element) that need to be parsed

Parameters:

  • destination_node (Nokogiri::Element)

    the element from the xml document that need to be parsed



22
23
24
# File 'lib/tax_generator/classes/destination.rb', line 22

def initialize(destination_node)
  @destination = destination_node
end

Instance Attribute Details

#destinationNokogiri::Element

Returns the element from the xml document that need to be parsed.

Returns:

  • (Nokogiri::Element)

    the element from the xml document that need to be parsed



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tax_generator/classes/destination.rb', line 7

class Destination
  include TaxGenerator::ApplicationHelper

  delegate :xpath,
           to: :destination

  attr_reader :destination

  # receives destination node (xml element) that need to be parsed
  #
  # @param  [Nokogiri::Element] destination_node the element from the xml document that need to be parsed
  #
  # @return [void]
  #
  # @api public
  def initialize(destination_node)
    @destination = destination_node
  end

  # returns the information about the introduction
  #
  # @return [Nokogiri::NodeSet]
  #
  # @api public
  def introduction
    xpath('.//introductory/introduction/overview')
  end

  # returns the information about the history
  #
  # @return [Nokogiri::NodeSet]
  #
  # @api public
  def history
    xpath('./history/history/history')
  end

  # returns the information about the practical_information
  #
  # @return [Nokogiri::NodeSet]
  #
  # @api public
  def practical_information
    base = './/practical_information/health_and_safety'
    xpath("#{base}/dangers_and_annoyances") + xpath("#{base}/while_youre_there") + \
      xpath("#{base}/before_you_go") + xpath("#{base}/money_and_costs/money")
  end

  # returns the information about the transport
  #
  # @return [Nokogiri::NodeSet]
  #
  # @api public
  def transport
    xpath('.//transport/getting_around')
  end

  # returns the information about the weather
  #
  # @return [Nokogiri::NodeSet]
  #
  # @api public
  def weather
    xpath('.//weather')
  end

  # returns the information about the work_live_study
  #
  # @return [Nokogiri::NodeSet]
  #
  # @api public
  def work_live_study
    xpath('.//work_live_study')
  end

  # returns the a hash containing all the parsed information from the xml document
  # and makes sure that only elements with content not blank will be returned
  #
  # @see #elements_with_content
  # @return [Nokogiri::NodeSet]
  #
  # @api public
  def to_hash
    {
      introduction: introduction,
      history: history,
      practical_information: practical_information,
      transport:  transport,
      weather: weather,
      work_live_study: work_live_study
    }.each_with_object({}) do |(key, value), hsh|
      hsh[key] = elements_with_content(value)
      hsh
    end
  end
end

Instance Method Details

#historyNokogiri::NodeSet

returns the information about the history

Returns:

  • (Nokogiri::NodeSet)


40
41
42
# File 'lib/tax_generator/classes/destination.rb', line 40

def history
  xpath('./history/history/history')
end

#introductionNokogiri::NodeSet

returns the information about the introduction

Returns:

  • (Nokogiri::NodeSet)


31
32
33
# File 'lib/tax_generator/classes/destination.rb', line 31

def introduction
  xpath('.//introductory/introduction/overview')
end

#practical_informationNokogiri::NodeSet

returns the information about the practical_information

Returns:

  • (Nokogiri::NodeSet)


49
50
51
52
53
# File 'lib/tax_generator/classes/destination.rb', line 49

def practical_information
  base = './/practical_information/health_and_safety'
  xpath("#{base}/dangers_and_annoyances") + xpath("#{base}/while_youre_there") + \
    xpath("#{base}/before_you_go") + xpath("#{base}/money_and_costs/money")
end

#to_hashNokogiri::NodeSet

returns the a hash containing all the parsed information from the xml document and makes sure that only elements with content not blank will be returned

Returns:

  • (Nokogiri::NodeSet)

See Also:

  • ApplicationHelper#elements_with_content


89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/tax_generator/classes/destination.rb', line 89

def to_hash
  {
    introduction: introduction,
    history: history,
    practical_information: practical_information,
    transport:  transport,
    weather: weather,
    work_live_study: work_live_study
  }.each_with_object({}) do |(key, value), hsh|
    hsh[key] = elements_with_content(value)
    hsh
  end
end

#transportNokogiri::NodeSet

returns the information about the transport

Returns:

  • (Nokogiri::NodeSet)


60
61
62
# File 'lib/tax_generator/classes/destination.rb', line 60

def transport
  xpath('.//transport/getting_around')
end

#weatherNokogiri::NodeSet

returns the information about the weather

Returns:

  • (Nokogiri::NodeSet)


69
70
71
# File 'lib/tax_generator/classes/destination.rb', line 69

def weather
  xpath('.//weather')
end

#work_live_studyNokogiri::NodeSet

returns the information about the work_live_study

Returns:

  • (Nokogiri::NodeSet)


78
79
80
# File 'lib/tax_generator/classes/destination.rb', line 78

def work_live_study
  xpath('.//work_live_study')
end