public string Select(string propertyName) { var desc = apiResource.GetDescription(propertyName); var rawValue = apiResource.GetValue(propertyName); return(PropertyFormatterFactory.Create(desc).Format(rawValue, desc)); }
public void TestCreate() { IPropertyFormatter formatter; // 通貨 formatter = CreateFormatter("dividend", "配当金", "円"); Assert.IsTrue(formatter is NumericFormatter); formatter = CreateFormatter("assets", "総資産", "百万円"); Assert.IsTrue(formatter is MillionYenFormatter); // 数値 formatter = CreateFormatter("issued_share_num", "発行済株式総数", "株"); Assert.IsTrue(formatter is NumericFormatter); formatter = CreateFormatter("pbr", "PBR", "倍"); Assert.IsTrue(formatter is NumericFormatter); formatter = CreateFormatter("inventory_turnover", "棚卸資産回転期間", "日"); Assert.IsTrue(formatter is NumericFormatter); formatter = CreateFormatter("debt_monthly_sales_ratio", "有利子負債/月商比率", "ヶ月"); Assert.IsTrue(formatter is NumericFormatter); formatter = CreateFormatter("employee_num", "従業員数", "人"); Assert.IsTrue(formatter is NumericFormatter); // 割合 formatter = CreateFormatter("tangible_fixed_assets_turnover", "有形固定資産回転率", "%"); Assert.IsTrue(formatter is RatioFormatter); // その他 formatter = CreateFormatter("company_name", "社名", "なし"); Assert.IsTrue(formatter is InactionFormatter); // プロパティの定義を渡さなかったら常にInactionFormatter formatter = PropertyFormatterFactory.Create(null); Assert.IsTrue(formatter is InactionFormatter); }
public static string SelectFormattedValue(string propertyName, IApiResource apiResource, bool isRawValue = false, bool isWithUnit = false, bool useDefaultUnit = false) { string rawValue = apiResource.GetValue(propertyName); var description = apiResource.GetDescription(propertyName); if (isRawValue) { return(isWithUnit ? rawValue + description.Unit : rawValue); } else { if (useDefaultUnit) { // 定義済みの「円」単位の数値は 100万円に変換する if (DefaultUnitConfig.MillionYenProperties.Contains(description.Name) && description.Unit.Equals("円")) { description = new PropertyDescription(description.Name, description.JpName, "百万円"); } } var formatter = PropertyFormatterFactory.Create(description); string formattedValue = formatter.Format(rawValue, description); return(isWithUnit ? formattedValue + description.Unit : formattedValue); } }
private IPropertyFormatter CreateFormatter(string name, string label, string unit) { PropertyDescription description = new PropertyDescription(name, label, unit); return(PropertyFormatterFactory.Create(description)); }