getPalace function

IFunctionalPalace? getPalace(
  1. IFunctionalAstrolabe astrolabe,
  2. dynamic indexOfPalace
)

获取星盘的某一个宫位

@version v1.0.0

@param $ 星盘实例 @param indexOrName 宫位索引或者宫位名称 @returns 宫位实例

Implementation

IFunctionalPalace? getPalace(
    IFunctionalAstrolabe astrolabe, dynamic indexOfPalace) {
  IFunctionalPalace? palace;
  if (indexOfPalace is int) {
    if (indexOfPalace != null) {
      if (indexOfPalace < 0 || indexOfPalace > 11) {
        throw Exception("invalid palace index");
      }
      palace = astrolabe.palaces.elementAt(indexOfPalace);
    }
  } else if (indexOfPalace is PalaceName) {
    palace = astrolabe.palaces.firstWhere((item) {
      if (item!.isOriginalPalace && indexOfPalace?.key == "originalPalace") {
        return true;
      }
      if (item!.isBodyPalace && indexOfPalace?.key == "bodyPalace") {
        return true;
      }
      if (item.name.key == indexOfPalace.key) {
        return true;
      }
      return false;
    });
  }

  palace?.setAstrolabe(astrolabe);
  return palace;
}