Module: Emvoicer::Services::BlinksaleParsing

Included in:
Blinksale
Defined in:
lib/emvoicer/services/blinksale/parsing.rb

Instance Method Summary collapse

Instance Method Details

#extract_client_node(source) ⇒ Object



24
25
26
27
# File 'lib/emvoicer/services/blinksale/parsing.rb', line 24

def extract_client_node(source)
  doc = Nokogiri::XML(source)
  doc.xpath("//xmlns:client").first
end

#extract_invoice_nodes(source) ⇒ Object



6
7
8
9
# File 'lib/emvoicer/services/blinksale/parsing.rb', line 6

def extract_invoice_nodes(source)
  doc = Nokogiri::XML(source)
  doc.xpath("//xmlns:invoice")
end

#parse_client(nokogiri_element) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/emvoicer/services/blinksale/parsing.rb', line 29

def parse_client(nokogiri_element)
  {
    :id => nokogiri_element.attributes["uri"].content[/\d+$/].to_i,
    :name => nokogiri_element.xpath('xmlns:name').first.content,
    :address1 => nokogiri_element.xpath("xmlns:address1").first.content,
    :address2 => nokogiri_element.xpath("xmlns:address2").first.content,
    :city => nokogiri_element.xpath("xmlns:city").first.content,
    :state => nokogiri_element.xpath("xmlns:state").first.content,
    :zip_code => nokogiri_element.xpath("xmlns:zip").first.content,
    :country => nokogiri_element.xpath("xmlns:country").first.content,
    :phone => nokogiri_element.xpath("xmlns:phone").first.content
  }
end

#parse_invoice(nokogiri_element) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/emvoicer/services/blinksale/parsing.rb', line 11

def parse_invoice(nokogiri_element)
  {
    :id => nokogiri_element.attributes["uri"].content[/\d+$/].to_i,
    :number => nokogiri_element.xpath("xmlns:number").first.content,
    :total_amount => nokogiri_element.attributes["total"].content.to_f,
    :due_amount => nokogiri_element.attributes["total_due"].content.to_f,
    :issued_on => Date.strptime(nokogiri_element.xpath("xmlns:date").first.content, "%Y-%m-%d"),
    :due_on => Date.strptime(nokogiri_element.xpath("xmlns:terms").first.attributes["due_date"].content, "%Y-%m-%d"),
    :currency => nokogiri_element.xpath("xmlns:currency").first.content,
    :client_id => nokogiri_element.xpath("xmlns:client").first.content[/\d+$/].to_i
  }
end