module JosieHealth::LUT::CaffeineLUT

Defined in:

caffeine_lut.cr

Constant Summary

CATEGORY_DEFAULTS = {"energy_drink" => {caffeine_mg: 160, default_ml: 500}, "energy_shot" => {caffeine_mg: 200, default_ml: 60}, "coffee" => {caffeine_mg: 95, default_ml: 240}, "tea" => {caffeine_mg: 50, default_ml: 240}, "soda" => {caffeine_mg: 40, default_ml: 355}}

Category defaults

SERVING_SIZES = {"can" => 355, "cans" => 355, "bottle" => 500, "bottles" => 500, "cup" => 240, "cups" => 240, "mug" => 350, "mugs" => 350, "shot" => 30, "shots" => 30}

Serving sizes in ml

Class Method Summary

Class Method Detail

def self.all_brands : Array(String) #

Get all brand names


def self.calculate_dose(dosage : String, substance : String) : NamedTuple(caffeine_mg: Float64, annotation: String) | Nil #

Full caffeine dose calculation Input: dosage string, substance name Returns: {caffeine_mg, annotation} or nil


def self.calculate_mg(volume_ml : Float64, caffeine_per_serving : Int32, serving_ml : Int32) : Float64 #

Calculate caffeine mg from volume and brand info


def self.get_category_defaults(category : String) : NamedTuple(caffeine_mg: Int32, default_ml: Int32) | Nil #

Get category defaults


def self.is_caffeine_source?(name : String) : Bool #

Check if a substance is a caffeinated beverage/product


def self.load_data #

Load caffeine data from embedded JSON


def self.lookup_brand(name : String) : NamedTuple(caffeine_mg: Int32, category: String, default_ml: Int32) | Nil #

Lookup a brand by name (handles aliases)


def self.lookup_powder_mg_per_g(name : String) : Int32 | Nil #

Lookup caffeine mg per gram for powder sources (e.g., matcha)


def self.parse_dosage(dosage : String) : NamedTuple(count: Int32, serving: String | Nil, volume_ml: Int32) | Nil #

Parse dosage string like "2cans", "500ml", "1cup", "2g" Returns {count, serving_type, volume_ml} or nil if not parseable Note: for "g" serving, count is truncated to Int32; use the original dosage string for precise weight


def self.resolve_alias(name : String) : String #

Resolve alias to canonical name