/* @preserve Brauhaus.js BeerXML Plugin Copyright 2013 Daniel G. Taylor https://github.com/homebrewing/brauhausjs-beerxml */ !function(){var Brauhaus,DOMParser,_ref,_ref1;Brauhaus=(_ref=this.Brauhaus)!=null?_ref:require("brauhaus");DOMParser=(_ref1=typeof window!=="undefined"&&window!==null?window.DOMParser:void 0)!=null?_ref1:require("xmldom").DOMParser;Brauhaus.Recipe.fromBeerXml=function(xml){var doc,fermentable,fermentableNode,fermentableProperty,mash,mashProperty,parser,recipe,recipeNode,recipeProperty,recipes,spice,spiceNode,spiceProperty,step,stepNode,stepProperty,styleNode,yeast,yeastNode,yeastProperty,_i,_j,_k,_l,_len,_len1,_len10,_len11,_len2,_len3,_len4,_len5,_len6,_len7,_len8,_len9,_m,_n,_o,_p,_q,_r,_ref10,_ref11,_ref12,_ref13,_ref14,_ref2,_ref3,_ref4,_ref5,_ref6,_ref7,_ref8,_ref9,_s,_t;recipes=[];parser=new DOMParser;doc=parser.parseFromString(xml,"text/xml");_ref2=doc.documentElement.childNodes||[];for(_i=0,_len=_ref2.length;_i<_len;_i++){recipeNode=_ref2[_i];if(recipeNode.nodeName.toLowerCase()!=="recipe"){continue}recipe=new Brauhaus.Recipe;_ref3=recipeNode.childNodes||[];for(_j=0,_len1=_ref3.length;_j<_len1;_j++){recipeProperty=_ref3[_j];switch(recipeProperty.nodeName.toLowerCase()){case"name":recipe.name=recipeProperty.textContent;break;case"brewer":recipe.author=recipeProperty.textContent;break;case"batch_size":recipe.batchSize=parseFloat(recipeProperty.textContent);break;case"boil_size":recipe.boilSize=parseFloat(recipeProperty.textContent);break;case"efficiency":recipe.mashEfficiency=parseFloat(recipeProperty.textContent);break;case"primary_age":recipe.primaryDays=parseFloat(recipeProperty.textContent);break;case"primary_temp":recipe.primaryTemp=parseFloat(recipeProperty.textContent);break;case"secondary_age":recipe.secondaryDays=parseFloat(recipeProperty.textContent);break;case"secondary_temp":recipe.secondaryTemp=parseFloat(recipeProperty.textContent);break;case"tertiary_age":recipe.tertiaryDays=parseFloat(recipeProperty.textContent);break;case"tertiary_temp":recipe.tertiaryTemp=parseFloat(recipeProperty.textContent);break;case"carbonation":recipe.bottlingPressure=parseFloat(recipeProperty.textContent);break;case"carbonation_temp":recipe.bottlingTemp=parseFloat(recipeProperty.textContent);break;case"age":recipe.agingDays=parseFloat(recipeProperty.textContent);break;case"age_temp":recipe.agingTemp=parseFloat(recipeProperty.textContent);break;case"style":recipe.style={og:[1,1.15],fg:[1,1.15],ibu:[0,150],color:[0,500],abv:[0,14],carb:[1,4]};_ref4=recipeProperty.childNodes||[];for(_k=0,_len2=_ref4.length;_k<_len2;_k++){styleNode=_ref4[_k];switch(styleNode.nodeName.toLowerCase()){case"name":recipe.style.name=styleNode.textContent;break;case"category":recipe.style.category=styleNode.textContent;break;case"og_min":recipe.style.og[0]=parseFloat(styleNode.textContent);break;case"og_max":recipe.style.og[1]=parseFloat(styleNode.textContent);break;case"fg_min":recipe.style.fg[0]=parseFloat(styleNode.textContent);break;case"fg_max":recipe.style.fg[1]=parseFloat(styleNode.textContent);break;case"ibu_min":recipe.style.ibu[0]=parseFloat(styleNode.textContent);break;case"ibu_max":recipe.style.ibu[1]=parseFloat(styleNode.textContent);break;case"color_min":recipe.style.color[0]=parseFloat(styleNode.textContent);break;case"color_max":recipe.style.color[1]=parseFloat(styleNode.textContent);break;case"abv_min":recipe.style.abv[0]=parseFloat(styleNode.textContent);break;case"abv_max":recipe.style.abv[1]=parseFloat(styleNode.textContent);break;case"carb_min":recipe.style.carb[0]=parseFloat(styleNode.textContent);break;case"carb_max":recipe.style.carb[1]=parseFloat(styleNode.textContent)}}break;case"fermentables":_ref5=recipeProperty.childNodes||[];for(_l=0,_len3=_ref5.length;_l<_len3;_l++){fermentableNode=_ref5[_l];if(fermentableNode.nodeName.toLowerCase()!=="fermentable"){continue}fermentable=new Brauhaus.Fermentable;_ref6=fermentableNode.childNodes||[];for(_m=0,_len4=_ref6.length;_m<_len4;_m++){fermentableProperty=_ref6[_m];switch(fermentableProperty.nodeName.toLowerCase()){case"name":fermentable.name=fermentableProperty.textContent;break;case"amount":fermentable.weight=parseFloat(fermentableProperty.textContent);break;case"yield":fermentable["yield"]=parseFloat(fermentableProperty.textContent);break;case"color":fermentable.color=parseFloat(fermentableProperty.textContent);break;case"add_after_boil":fermentable.late=fermentableProperty.textContent.toLowerCase()==="true"}}recipe.fermentables.push(fermentable)}break;case"hops":case"miscs":_ref7=recipeProperty.childNodes||[];for(_n=0,_len5=_ref7.length;_n<_len5;_n++){spiceNode=_ref7[_n];if((_ref8=spiceNode.nodeName.toLowerCase())!=="hop"&&_ref8!=="misc"){continue}spice=new Brauhaus.Spice;_ref9=spiceNode.childNodes||[];for(_o=0,_len6=_ref9.length;_o<_len6;_o++){spiceProperty=_ref9[_o];switch(spiceProperty.nodeName.toLowerCase()){case"name":spice.name=spiceProperty.textContent;break;case"amount":spice.weight=parseFloat(spiceProperty.textContent);break;case"alpha":spice.aa=parseFloat(spiceProperty.textContent);break;case"use":spice.use=spiceProperty.textContent;break;case"form":spice.form=spiceProperty.textContent}}recipe.spices.push(spice)}break;case"yeasts":_ref10=recipeProperty.childNodes||[];for(_p=0,_len7=_ref10.length;_p<_len7;_p++){yeastNode=_ref10[_p];if(yeastNode.nodeName.toLowerCase()!=="yeast"){continue}yeast=new Brauhaus.Yeast;_ref11=yeastNode.childNodes||[];for(_q=0,_len8=_ref11.length;_q<_len8;_q++){yeastProperty=_ref11[_q];switch(yeastProperty.nodeName.toLowerCase()){case"name":yeast.name=yeastProperty.textContent;break;case"type":yeast.type=yeastProperty.textContent;break;case"form":yeast.form=yeastProperty.textContent;break;case"attenuation":yeast.attenuation=parseFloat(yeastProperty.textContent)}}recipe.yeast.push(yeast)}break;case"mash":mash=recipe.mash=new Brauhaus.Mash;_ref12=recipeProperty.childNodes||[];for(_r=0,_len9=_ref12.length;_r<_len9;_r++){mashProperty=_ref12[_r];switch(mashProperty.nodeName.toLowerCase()){case"name":mash.name=mashProperty.textContent;break;case"grain_temp":mash.grainTemp=parseFloat(mashProperty.textContent);break;case"sparge_temp":mash.spargeTemp=parseFloat(mashProperty.textContent);break;case"ph":mash.ph=parseFloat(mashProperty.textContent);break;case"notes":mash.notes=mashProperty.textContent;break;case"mash_steps":_ref13=mashProperty.childNodes||[];for(_s=0,_len10=_ref13.length;_s<_len10;_s++){stepNode=_ref13[_s];if(stepNode.nodeName.toLowerCase()!=="mash_step"){continue}step=new Brauhaus.MashStep;_ref14=stepNode.childNodes||[];for(_t=0,_len11=_ref14.length;_t<_len11;_t++){stepProperty=_ref14[_t];switch(stepProperty.nodeName.toLowerCase()){case"name":step.name=stepProperty.textContent;break;case"type":step.type=stepProperty.textContent;break;case"infuse_amount":step.waterRatio=parseFloat(stepProperty.textContent)/recipe.grainWeight();break;case"step_temp":step.temp=parseFloat(stepProperty.textContent);break;case"end_temp":step.endTemp=parseFloat(stepProperty.textContent);break;case"step_time":step.time=parseFloat(stepProperty.textContent);break;case"decoction_amt":step.waterRatio=parseFloat(stepProperty.textContent)/recipe.grainWeight()}}mash.steps.push(step)}}}}}recipes.push(recipe)}return recipes};Brauhaus.Recipe.prototype.toBeerXml=function(){var fermentable,hop,misc,step,xml,yeast,_i,_j,_k,_l,_len,_len1,_len2,_len3,_len4,_m,_ref2,_ref3,_ref4,_ref5,_ref6;xml='';xml+="1";xml+=""+this.name+"";xml+=""+this.author+"";xml+=""+this.batchSize+"";xml+=""+this.boilSize+"";xml+=""+this.mashEfficiency+"";if(this.primaryDays){xml+=""+this.primaryDays+""}if(this.primaryTemp){xml+=""+this.primaryTemp+""}if(this.secondaryDays){xml+=""+this.secondaryDays+""}if(this.secondaryTemp){xml+=""+this.secondaryTemp+""}if(this.tertiaryDays){xml+=""+this.tertiaryDays+""}if(this.tertiaryTemp){xml+=""+this.tertiaryTemp+""}if(this.agingDays){xml+=""+this.agingDays+""}if(this.agingTemp){xml+=""+this.agingTemp+""}if(this.bottlingTemp){xml+=""+this.bottlingTemp+""}if(this.bottlingPressure){xml+=""+this.bottlingPressure+""}if(this.style){xml+=""}xml+="";_ref2=this.fermentables;for(_i=0,_len=_ref2.length;_i<_len;_i++){fermentable=_ref2[_i];xml+="1";xml+=""+fermentable.name+"";xml+=""+fermentable.type()+"";xml+=""+fermentable.weight.toFixed(1)+"";xml+=""+fermentable["yield"].toFixed(1)+"";xml+=""+fermentable.color.toFixed(1)+"";xml+=""}xml+="";xml+="";_ref3=this.spices.filter(function(item){return item.aa>0});for(_j=0,_len1=_ref3.length;_j<_len1;_j++){hop=_ref3[_j];xml+="1";xml+=""+hop.name+"";xml+="";xml+=""+hop.weight+"";xml+=""+hop.aa.toFixed(2)+"";xml+=""+hop.use+"";xml+="
"+hop.form+"
";xml+="
"}xml+="
";xml+="";_ref4=this.yeast;for(_k=0,_len2=_ref4.length;_k<_len2;_k++){yeast=_ref4[_k];xml+="1";xml+=""+yeast.name+"";xml+=""+yeast.type+"";xml+="
"+yeast.form+"
";xml+=""+yeast.attenuation+"";xml+="
"}xml+="
";xml+="";_ref5=this.spices.filter(function(item){return item.aa===0});for(_l=0,_len3=_ref5.length;_l<_len3;_l++){misc=_ref5[_l];xml+="1";xml+=""+misc.name+"";xml+="";xml+=""+misc.weight+"";xml+=""+misc.use+"";xml+=""}xml+="";if(this.mash){xml+="1";xml+=""+this.mash.name+"";xml+=""+this.mash.grainTemp+"";xml+=""+this.mash.spargeTemp+"";xml+=""+this.mash.ph+"";xml+=""+this.mash.notes+"";xml+="";_ref6=this.mash.steps;for(_m=0,_len4=_ref6.length;_m<_len4;_m++){step=_ref6[_m];xml+="1";xml+=""+step.name+"";xml+=""+step.description(true,this.grainWeight())+"";xml+=""+step.time+"";xml+=""+step.temp+"";xml+=""+step.endTemp+"";xml+=""+step.rampTime+"";if(step.type==="Decoction"){xml+=""+step.waterRatio*this.grainWeight()+""}else{xml+=""+step.waterRatio*this.grainWeight()+""}xml+=""}xml+="";xml+=""}return xml+="
"}}.call(this);