Skip to content

servings/yield should allow floating-point numbers #82

Description

@tomodachi94

I have a recipe that has a yield of 1.75 cups, and I marked it as such in the metadata:

---
servings: 1.75 # cup
---

Some instructions...

However, the playground gives me a warning:

Warning: Unsupported value for key: 'servings'
  ╰▶  Expected 'number' but got 'number'
  ╭─[playground]
  │
2 │ servings: 1.75 # cup
  ┆ ─                   
──╯

And scaling doesn't work (behaves as if servings: 1 is set).

It looks like this is because the as_servings function in metadata.rs only tries u32 and string:

cooklang-rs/src/metadata.rs

Lines 393 to 397 in b86eec6

fn as_servings(&self) -> Option<Servings> {
// Try as number first
if let Some(n) = self.as_u32() {
return Some(Servings::Number(n));
}

Workaround

I could change the unit to be a whole number, but this isn't ideal.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions