Skip to content

Commit

Permalink
Added age category builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Meshulam Silk committed Apr 12, 2015
1 parent cb6a46d commit 238717f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/geek_code_312.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ part "src/312/categories/sex_geek_code_category.dart";
part "src/312/categories/unix_geek_code_category.dart";
part "src/312/categories/dress_geek_code_category.dart";
part "src/312/categories/shape_geek_code_category.dart";
part "src/312/categories/age_geek_code_category.dart";
part "src/312/geek_code_types.dart";
part "src/312/geek_code_v312_categories.dart";
58 changes: 58 additions & 0 deletions lib/src/312/categories/age_geek_code_category.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2015, Meshulam Silk ([email protected]). All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of geek_code.v312;

/**
* Class that builds [DressGeekCodeCategory]s.
*
* Adds 2 variable setting methods:
*
* * [crossDresser]
* * [sameClothes]
*/
class AgeGeekCodeCategoryBuilder extends GeekCodeCategoryBuilder {
int _age;

/**
* Creates a new [DressGeekCodeCategoryBuilder] object.
*
* See [GeekCodeCategoryBuilder.GeekCodeCategoryBuilder] for a description of the parameters.
*/
AgeGeekCodeCategoryBuilder(String code, int minGrade, int maxGrade) : super(code, minGrade, maxGrade);

/**
* Original documentation:
*
* In addition, if you wish to give your exact age, you can place the number after the 'a' identifier. For example: a42
*/
AgeGeekCodeCategory age(int age) {
this._age = age;
return subValidate(null, false, false);
}

/**
* Returns a [DressGeekCodeCategory] without performing any additional validations.
*
* See [GeekCodeCategoryBuilder.subValidate] for a fuller explanation of this method.
*/
AgeGeekCodeCategory subValidate(GeekCodeGrade grade, bool refuse, bool noKnowledge) => new AgeGeekCodeCategory(this, grade);
}

/**
* Original documentation:
*
* It is said that "clothes make the man". Well, I understood that I was made by a mommy and a daddy (and there's even a category to describe the process below!). Maybe the people who made up that saying aren't being quite that literal...
*/
class AgeGeekCodeCategory extends GeekCodeCategory {
final AgeGeekCodeCategoryBuilder _builder;

/**
* See [GeekCodeCategory.GeekCodeCategory] for a description of the parameters.
*/
AgeGeekCodeCategory(AgeGeekCodeCategoryBuilder builder, GeekCodeGrade grade)
: this._builder = builder,
super(builder, grade);

String toString() => super.toString() + "${_builder._age}";
}
2 changes: 1 addition & 1 deletion lib/src/312/categories/dress_geek_code_category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DressGeekCodeCategory extends GeekCodeCategory {
/**
* See [GeekCodeCategory.GeekCodeCategory] for a description of the parameters.
*/
DressGeekCodeCategory(builder, GeekCodeGrade grade)
DressGeekCodeCategory(DressGeekCodeCategoryBuilder builder, GeekCodeGrade grade)
: this._builder = builder,
super(builder, grade) {
if (_builder._crossDresser) super.code += "x";
Expand Down
6 changes: 2 additions & 4 deletions lib/src/312/geek_code_v312_categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ final ShapeGeekCodeCategoryBuilder s = getBuilder("s") as ShapeGeekCodeCategoryB
* it's none of your business how old I am
*
* In addition, if you wish to give your exact age, you can place the number after the 'a' identifier. For example: a42
*
* Note: Providing exact age is not supported currently.
*/
final GenericGeekCodeCategoryBuilder a = getBuilder("a") as GenericGeekCodeCategoryBuilder; //TODO: Support exact age
final AgeGeekCodeCategoryBuilder a = getBuilder("a") as AgeGeekCodeCategoryBuilder;

/**
* Builds the Computers category.
Expand Down Expand Up @@ -815,7 +813,7 @@ GeekCodeCategoryBuilder getBuilder(String categoryCode) {
return new ShapeGeekCodeCategoryBuilder("s", -3, 3);

case "a":
return new GenericGeekCodeCategoryBuilder("a", -5, 3);
return new AgeGeekCodeCategoryBuilder("a", -5, 3);

case "C":
return new GenericGeekCodeCategoryBuilder("C", -3, 4);
Expand Down
2 changes: 1 addition & 1 deletion test/all_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ main() {
GeekCodeV312 code = new GeekCodeV312([G312.IT, G312.CS, G312.B, G312.C] as List<GeekCodeType>)
..addCategory(d.refuse())
..addCategory(s.refuse())
..addCategory(a.grade(new GeekCodeGrade(-3)))
..addCategory(a.age(20))
..addCategory(C.grade(new GeekCodeGrade(2)))
..addCategory(U.refuse())
..addCategory(P.noKnowledge())
Expand Down

0 comments on commit 238717f

Please sign in to comment.