require "./spec_helper" describe JosieHealth::Utils::Formatting do describe ".format_float" do it "removes .0 from whole numbers" do JosieHealth::Utils::Formatting.format_float(5.0).should eq("5") end it "keeps decimals for non-whole numbers" do JosieHealth::Utils::Formatting.format_float(5.5).should eq("5.5") end it "rounds to 1 decimal place" do JosieHealth::Utils::Formatting.format_float(5.123).should eq("5.1") end it "handles zero" do JosieHealth::Utils::Formatting.format_float(0.0).should eq("0") end end describe ".format_dosage" do it "removes .0 from whole number dosages" do JosieHealth::Utils::Formatting.format_dosage("95.0mg").should eq("95mg") end it "removes .0 with trailing text" do JosieHealth::Utils::Formatting.format_dosage("100.0mg total").should eq("100mg total") end it "keeps non-.0 decimals" do JosieHealth::Utils::Formatting.format_dosage("95.5mg").should eq("95.5mg") end it "handles multiple values" do JosieHealth::Utils::Formatting.format_dosage("100.0mg + 50.0mg").should eq("100mg + 50mg") end it "handles no unit" do JosieHealth::Utils::Formatting.format_dosage("100.0").should eq("100") end end describe ".time_ago" do it "formats minutes only" do now = Time.utc(2025, 1, 1, 12, 30, 0) time = Time.utc(2025, 1, 1, 12, 15, 0) JosieHealth::Utils::Formatting.time_ago(time, now).should eq("15m ago") end it "formats hours and minutes" do now = Time.utc(2025, 1, 1, 14, 30, 0) time = Time.utc(2025, 1, 1, 12, 15, 0) JosieHealth::Utils::Formatting.time_ago(time, now).should eq("2h15m ago") end it "formats hours only when no minutes" do now = Time.utc(2025, 1, 1, 14, 0, 0) time = Time.utc(2025, 1, 1, 12, 0, 0) JosieHealth::Utils::Formatting.time_ago(time, now).should eq("2h ago") end it "formats days and hours" do now = Time.utc(2025, 1, 3, 14, 0, 0) time = Time.utc(2025, 1, 1, 12, 0, 0) JosieHealth::Utils::Formatting.time_ago(time, now).should eq("2d2h ago") end it "formats days only when no hours" do now = Time.utc(2025, 1, 3, 12, 0, 0) time = Time.utc(2025, 1, 1, 12, 0, 0) JosieHealth::Utils::Formatting.time_ago(time, now).should eq("2d ago") end it "handles 0 minutes" do now = Time.utc(2025, 1, 1, 12, 0, 0) time = Time.utc(2025, 1, 1, 12, 0, 0) JosieHealth::Utils::Formatting.time_ago(time, now).should eq("0m ago") end end describe ".ordinalize" do it "handles 1st" do JosieHealth::Utils::Formatting.ordinalize(1).should eq("1st") end it "handles 2nd" do JosieHealth::Utils::Formatting.ordinalize(2).should eq("2nd") end it "handles 3rd" do JosieHealth::Utils::Formatting.ordinalize(3).should eq("3rd") end it "handles 4th" do JosieHealth::Utils::Formatting.ordinalize(4).should eq("4th") end it "handles 11th (special case)" do JosieHealth::Utils::Formatting.ordinalize(11).should eq("11th") end it "handles 12th (special case)" do JosieHealth::Utils::Formatting.ordinalize(12).should eq("12th") end it "handles 13th (special case)" do JosieHealth::Utils::Formatting.ordinalize(13).should eq("13th") end it "handles 21st" do JosieHealth::Utils::Formatting.ordinalize(21).should eq("21st") end it "handles 22nd" do JosieHealth::Utils::Formatting.ordinalize(22).should eq("22nd") end it "handles 23rd" do JosieHealth::Utils::Formatting.ordinalize(23).should eq("23rd") end it "handles 111th (special case)" do JosieHealth::Utils::Formatting.ordinalize(111).should eq("111th") end it "handles 112th (special case)" do JosieHealth::Utils::Formatting.ordinalize(112).should eq("112th") end it "handles 113th (special case)" do JosieHealth::Utils::Formatting.ordinalize(113).should eq("113th") end end end describe Int32 do describe "#ordinalize" do it "adds ordinalize method to Int32" do 1.ordinalize.should eq("1st") 2.ordinalize.should eq("2nd") 3.ordinalize.should eq("3rd") 4.ordinalize.should eq("4th") 11.ordinalize.should eq("11th") end end end