# File lib/fishing_list_format.rb, line 24 def primary_sites(sites) Array(sites).select { |site| site["PS_FLAG"] == "P" } end
module FishingListFormat
Constants
- REGION_BANDS
- REGION_ORDER
Public Instance Methods
Source
# File lib/fishing_list_format.rb, line 52 def build_list_body(sites, max_bytes: RabbotConfig::PRIVMSG_CHUNK_BYTES) grouped = group_by_region(sites) REGION_ORDER.flat_map do |region| names = grouped[region] next [] if names.nil? || names.empty? build_region_lines(region, names, max_bytes: max_bytes) end end
Source
# File lib/fishing_list_format.rb, line 41 def build_region_lines(region, names, max_bytes: RabbotConfig::PRIVMSG_CHUNK_BYTES) prefix = "#{region} — " prefix_bytes = prefix.bytesize budget = [max_bytes - prefix_bytes, 20].max packed = ParagraphFormat.build_paragraphs(names, max_bytes: budget, separator: ", ") return [] if packed.empty? packed[0] = "#{prefix}#{packed[0]}" packed end
Source
# File lib/fishing_list_format.rb, line 32 def group_by_region(sites) grouped = Hash.new { |hash, key| hash[key] = [] } primary_sites(sites).each do |site| region = region_for_lat(site["LAT"]) grouped[region] << site["PORT_NAME"] end grouped.transform_values { |names| names.sort } end
Source
Source
# File lib/fishing_list_format.rb, line 28 def region_for_lat(lat) REGION_BANDS.find { |_name, max| lat.to_f > max }&.first || "South East" end