class AMarmita::Cart::Base

Public Instance Methods

add_item(id, date = nil, quantity = nil) click to toggle source
# File lib/a_marmita/cart/base.rb, line 24
def add_item(id, date = nil, quantity = nil)
  return :bad_login if cant_log_in?
  
  quantity = 1 if Helpers.blank?(quantity)
  date = Helpers.format_date(date)

  server_response = get_page_body("http://www.amarmita.com/enc.php?id=#{id}&qtd=#{quantity}&data=#{date}&op=1")

  { "1" => :ok, "-2" => :bad_date }[server_response] || :error
end
checkout(payment_method) click to toggle source
# File lib/a_marmita/cart/base.rb, line 51
def checkout(payment_method)
  return :bad_login if cant_log_in?

  case payment_method.to_s
  when "through_mb"
    client.payment.through_mb
  when "end_of_month"
    client.payment.end_of_month
  else
    :unknown_payment_method
  end
end
items() click to toggle source
# File lib/a_marmita/cart/base.rb, line 8
def items
  return :bad_login if cant_log_in?

  page, last_date = get_page("http://www.amarmita.com/enc.php?op=4"), ''

  content_rows = page.parser.css('table > tr')
  
  content_rows.map do |row|
    new_date = row.css('.em_marmitalist_data')

    last_date = Helpers.cart_date_parser(new_date.first.text) unless new_date.empty?

    Cart::Scrapper.new(row).scrap(date: last_date)
  end.compact
end
remove_item(id) click to toggle source
# File lib/a_marmita/cart/base.rb, line 35
def remove_item(id)
  return :bad_login if cant_log_in?
  
  server_response = get_page_body("http://www.amarmita.com/enc.php?id=#{id}&op=2")

  server_response == "1" ? :ok : :error
end
total() click to toggle source
# File lib/a_marmita/cart/base.rb, line 43
def total
  return :bad_login if cant_log_in?
  
  total = get_page_body("http://www.amarmita.com/enc.php?op=5")

  Helpers.to_float(total).first
end