Class: Reelagram::Mail::Parsers::ShippingParser
- Inherits:
-
Object
- Object
- Reelagram::Mail::Parsers::ShippingParser
- Defined in:
- lib/reelagram/mail/parsers/shipping_parser.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
- #carrier ⇒ Object
-
#initialize ⇒ ShippingParser
constructor
A new instance of ShippingParser.
- #order_number ⇒ Object
- #reset! ⇒ Object
- #run(string) ⇒ Object
- #tracking_link ⇒ Object
- #tracking_number ⇒ Object
Constructor Details
#initialize ⇒ ShippingParser
Returns a new instance of ShippingParser.
9 10 11 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 9 def initialize @debug = Reelagram::Mail.debug? end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
7 8 9 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 7 def debug @debug end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
7 8 9 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 7 def doc @doc end |
Instance Method Details
#carrier ⇒ Object
19 20 21 22 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 19 def carrier return "Unavailable" unless shipping_info_row @row.children[0].text end |
#order_number ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 40 def order_number return unless table = doc.css("table")[2] table.css("tr") .children.css("td") .children .text .gsub(/\\n+/, " ") .scan(/\w*/) .reject(&:empty?) .last end |
#reset! ⇒ Object
52 53 54 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 52 def reset! @shipping_info_table, @row = nil, nil end |
#run(string) ⇒ Object
13 14 15 16 17 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 13 def run(string) @doc = Nokogiri::HTML(string) log_parsed_data if debug self end |
#tracking_link ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 29 def tracking_link return unless shipping_info_row begin tracking_link_container.css("a") .attr("href") .value rescue nil end end |
#tracking_number ⇒ Object
24 25 26 27 |
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 24 def tracking_number return "Unavailable" unless shipping_info_row tracking_link_container.text end |