Class: Reelagram::Mail::Parsers::ShippingParser

Inherits:
Object
  • Object
show all
Defined in:
lib/reelagram/mail/parsers/shipping_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShippingParser

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

#debugObject (readonly)

Returns the value of attribute debug.



7
8
9
# File 'lib/reelagram/mail/parsers/shipping_parser.rb', line 7

def debug
  @debug
end

#docObject (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

#carrierObject



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_numberObject



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


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_numberObject



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