class TheCommunityFarm::OrganicBoxes::Box

Represents a single organic veg box.

Attributes

noko[R]

Public Class Methods

new(noko:) click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 7
def initialize(noko:)
  @noko = noko
end

Public Instance Methods

box_size() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 22
def box_size
  @box_size ||= begin
    size = noko.at_css('option[selected]')
    size && size.text && size.text.strip
  end
end
id() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 11
def id
  Digest::MD5.new.tap do |id|
    id.update(type)
    id.update(items.join("\n"))
  end.hexdigest
end
items() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 29
def items
  @items ||= item_doc.css('li').map { |li| li.text.strip }
end
name() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 33
def name
  "#{type} #{box_size}".strip
end
to_s() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 37
def to_s
  name
end
type() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 18
def type
  @type ||= noko.at_css('.lead').text.strip
end

Private Instance Methods

item_doc() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 45
def item_doc
  @item_doc ||= Nokogiri::HTML(noko.at_css(item_selector)['data-content'])
end
item_selector() click to toggle source
# File lib/the_community_farm/organic_boxes/box.rb, line 49
def item_selector
  %([data-content*="This week's contents"])
end