use super::types::{FormatType, NumberAlign, NumberFormat, Sign, Timezone};
impl NumberFormat {
pub fn new() -> NumberFormat {
NumberFormat::default()
}
pub fn zero_padding(mut self) -> NumberFormat {
self.zero_padding = true;
self
}
pub fn no_zero_padding(mut self) -> NumberFormat {
self.zero_padding = false;
self
}
pub fn fill(mut self, fill_char: char) -> NumberFormat {
self.fill = fill_char;
self
}
pub fn left_align(mut self) -> NumberFormat {
self.align = NumberAlign::Left;
self
}
pub fn right_align(mut self) -> NumberFormat {
self.align = NumberAlign::Right;
self
}
pub fn center_align(mut self) -> NumberFormat {
self.align = NumberAlign::Center;
self
}
pub fn left_sign_right_align(mut self) -> NumberFormat {
self.align = NumberAlign::SignedRight;
self
}
pub fn unsigned(mut self) -> NumberFormat {
self.sign = Sign::OnlyNegative;
self
}
pub fn signed(mut self) -> NumberFormat {
self.sign = Sign::Always;
self
}
pub fn unsigned_space(mut self) -> NumberFormat {
self.sign = Sign::SpaceOrDash;
self
}
pub fn type_prefix(mut self) -> NumberFormat {
self.type_prefix = true;
self
}
pub fn no_type_prefix(mut self) -> NumberFormat {
self.type_prefix = false;
self
}
pub fn width(mut self, width: usize) -> NumberFormat {
self.min_width = width;
self.max_width = width;
self
}
pub fn min_width(mut self, min_width: usize) -> NumberFormat {
self.min_width = min_width;
self
}
pub fn max_width(mut self, max_width: usize) -> NumberFormat {
self.max_width = max_width;
self
}
pub fn width_option(self, width: Option<usize>) -> NumberFormat {
self.min_width_option(width).max_width_option(width)
}
pub fn min_width_option(mut self, width: Option<usize>) -> NumberFormat {
match width {
Some(width) => {
self.min_width = width;
self
}
None => self,
}
}
pub fn max_width_option(mut self, width: Option<usize>) -> NumberFormat {
match width {
Some(width) => {
self.max_width = width;
self
}
None => self,
}
}
pub fn commas(mut self) -> NumberFormat {
self.commas = true;
self
}
pub fn no_commas(mut self) -> NumberFormat {
self.commas = false;
self
}
pub fn precision(mut self, precision: usize) -> NumberFormat {
self.precision = precision;
self
}
pub fn timezone_local(mut self) -> NumberFormat {
self.timezone = Timezone::Local;
self
}
pub fn timezone_utc(mut self) -> NumberFormat {
self.timezone = Timezone::Utc;
self
}
pub fn scientific_notation(mut self) -> NumberFormat {
self.format_type = FormatType::Exponent;
self
}
pub fn si(mut self) -> NumberFormat {
self.format_type = FormatType::SI;
self
}
pub fn percentage(mut self) -> NumberFormat {
self.format_type = FormatType::Percentage;
self
}
pub fn binary(mut self) -> NumberFormat {
self.format_type = FormatType::Binary;
self
}
pub fn octal(mut self) -> NumberFormat {
self.format_type = FormatType::Octal;
self
}
pub fn hex(mut self) -> NumberFormat {
self.format_type = FormatType::Octal;
self
}
pub fn integer_oom(mut self) -> NumberFormat {
self.format_type = FormatType::IntegerOrderOfMagnitude;
self
}
pub fn float_oom(mut self) -> NumberFormat {
self.format_type = FormatType::FloatOrderOfMagnitude;
self
}
pub fn timestamp(mut self) -> NumberFormat {
self.format_type = FormatType::TimestampPretty;
self
}
pub fn format_type(mut self, format_type: &FormatType) -> NumberFormat {
self.format_type = format_type.clone();
self
}
}