Returns int based on current flight rules from parsed METAR data

    0=VFR, 1=MVFR, 2=IFR, 3=LIFR

    Note: Common practice is to report IFR if visibility unavailable

def get_flight_rules(vis: Number, ceiling: Cloud) -> int:
    """
    Returns int based on current flight rules from parsed METAR data

    0=VFR, 1=MVFR, 2=IFR, 3=LIFR

    Note: Common practice is to report IFR if visibility unavailable
    """
    # Parse visibility
    if not vis:
        return 2
    if vis.repr == 'CAVOK' or vis.repr.startswith('P6'):
        vis = 10  # type: ignore
    elif vis.repr.startswith('M'):
        vis = 0  # type: ignore
    # Convert meters to miles
    elif len(vis.repr) == 4:
        vis = vis.value * 0.000621371  # type: ignore
    else:
        vis = vis.value  # type: ignore
    # Parse ceiling
    cld = ceiling.altitude if ceiling else 99
    # Determine flight rules
    if (vis <= 5) or (cld <= 30):  # type: ignore
        if (vis < 3) or (cld < 10):  # type: ignore
            if (vis < 1) or (cld < 5):  # type: ignore
                return 3  # LIFR
            return 2  # IFR
        return 1  # MVFR
    return 0