Class: OrderItem

Inherits:
Object
  • Object
show all
Defined in:
lib/order_review.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ OrderItem

Returns a new instance of OrderItem.



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/order_review.rb', line 57

def initialize(item)
  self.name = item.css(".orderItems_item_name").first.text.strip.gsub(/\s+/, " ")
  # TODO: Get toppings list

  details_element = item.css(".orderItems_item_detail")
  details_dt = details_element.css("dt").map { |t| t.text.strip.gsub(/\s+/, " ") }
  details_dd = details_element.css("dd").map { |t| t.text.strip.gsub(/\s+/, " ") }

  self.details = details_dt.zip(details_dd).to_h
  details["Price"] = item.css(".orderItems_item_price").text.strip.gsub(/\s+/, " ")
end

Instance Attribute Details

#detailsObject

Returns the value of attribute details.



55
56
57
# File 'lib/order_review.rb', line 55

def details
  @details
end

#nameObject

Returns the value of attribute name.



55
56
57
# File 'lib/order_review.rb', line 55

def name
  @name
end

Instance Method Details

#to_sObject



69
70
71
72
# File 'lib/order_review.rb', line 69

def to_s
  deets = details.map { |key, value| "  #{key}: #{value}" }.join("\n")
  "#{name.colorize(:blue)}\n#{deets}"
end