Class: TaxGenerator::Destination
- Inherits:
-
Object
- Object
- TaxGenerator::Destination
- 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
-
#destination ⇒ Nokogiri::Element
The element from the xml document that need to be parsed.
Instance Method Summary collapse
-
#history ⇒ Nokogiri::NodeSet
returns the information about the history.
-
#initialize(destination_node) ⇒ void
constructor
receives destination node (xml element) that need to be parsed.
-
#introduction ⇒ Nokogiri::NodeSet
returns the information about the introduction.
-
#practical_information ⇒ Nokogiri::NodeSet
returns the information about the practical_information.
-
#to_hash ⇒ Nokogiri::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.
-
#transport ⇒ Nokogiri::NodeSet
returns the information about the transport.
-
#weather ⇒ Nokogiri::NodeSet
returns the information about the weather.
-
#work_live_study ⇒ Nokogiri::NodeSet
returns the information about the work_live_study.
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, set_celluloid_exception_handling
Constructor Details
#initialize(destination_node) ⇒ void
receives destination node (xml element) 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
#destination ⇒ Nokogiri::Element
Returns 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
#history ⇒ Nokogiri::NodeSet
returns the information about the history
40 41 42 |
# File 'lib/tax_generator/classes/destination.rb', line 40 def history xpath('./history/history/history') end |
#introduction ⇒ Nokogiri::NodeSet
returns the information about the introduction
31 32 33 |
# File 'lib/tax_generator/classes/destination.rb', line 31 def introduction xpath('.//introductory/introduction/overview') end |
#practical_information ⇒ Nokogiri::NodeSet
returns the information about the practical_information
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_hash ⇒ Nokogiri::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
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 |
#transport ⇒ Nokogiri::NodeSet
returns the information about the transport
60 61 62 |
# File 'lib/tax_generator/classes/destination.rb', line 60 def transport xpath('.//transport/getting_around') end |
#weather ⇒ Nokogiri::NodeSet
returns the information about the weather
69 70 71 |
# File 'lib/tax_generator/classes/destination.rb', line 69 def weather xpath('.//weather') end |
#work_live_study ⇒ Nokogiri::NodeSet
returns the information about the work_live_study
78 79 80 |
# File 'lib/tax_generator/classes/destination.rb', line 78 def work_live_study xpath('.//work_live_study') end |