# -*- coding: utf-8 -*-

import random
import yaml


class name(object):
    def is_male(self):
        from gimei import MALE
        return self.gender == MALE

    def is_female(self):
        from gimei import FEMALE
        return self.gender == FEMALE

    @property
    def kanji(self):
        return self.all[0]

    @property
    def hiragana(self):
        return self.all[1]

    @property
    def katakana(self):
        return self.all[2]


class first_name(name):
    def __init__(self, gender=None):
        from gimei import GENDER
        from gimei import Gimei
        self.gender = gender if gender is not None else random.choice(GENDER)
        self.all = random.choice(Gimei.NAMES[self.__class__.__name__][self.gender])


class last_name(name):
    def __init__(self, gender=None):
        from gimei import GENDER
        from gimei import Gimei
        self.gender = gender if gender is not None else random.choice(GENDER)
        self.all = random.choice(Gimei.NAMES[self.__class__.__name__])


class Name(object):
    def __init__(self, gender=None):
        if gender is None:
            from gimei import GENDER
            gender = random.choice(GENDER)
        self.gender = gender
        self.first = first_name(self.gender)
        self.last = last_name(self.gender)

    @property
    def kanji(self):
        return u"{} {}".format(
            self.last.kanji,
            self.first.kanji,
        )

    @property
    def hiragana(self):
        return u"{} {}".format(
            self.last.hiragana,
            self.first.hiragana,
        )

    @property
    def katakana(self):
        return u"{} {}".format(
            self.last.katakana,
            self.first.katakana,
        )

    @property
    def is_male(self):
        from gimei import MALE
        return self.gender == MALE

    @property
    def is_female(self):
        from gimei import FEMALE
        return self.gender == FEMALE

    def __repr__(self):
        return self.kanji.encode('utf-8')

@@ -447,16 +447,135 @@
 all%5B2%5D%0A%0A
+    @classmethod%0A    def get_all_names(cls):%0A        from gimei import Gimei%0A        return Gimei.NAMES%5Bcls.__name__%5D%0A%0A
 %0Aclass f
@@ -2124,8 +2124,1197 @@
 utf-8')%0A
+%0A    @classmethod%0A    def find_name_by_index(cls, name, idx):%0A        from gimei import MALE, FEMALE%0A        result = %5B%5D%0A%0A        token = name.split(' ')%0A        if len(token) != 2:%0A            return None%0A        first_names = first_name.get_all_names()%0A        last_names = last_name.get_all_names()%0A%0A        for _names in last_names:%0A            if _names%5Bidx%5D == token%5B0%5D:%0A                result.append(_names%5Bidx%5D)%0A                break%0A%0A        for _names in first_names%5BMALE%5D:%0A            if _names%5Bidx%5D == token%5B1%5D:%0A                result.append(token%5B1%5D)%0A                break%0A%0A        if len(result) != 2:%0A            for _names in first_names%5BFEMALE%5D:%0A                if _names%5Bidx%5D == token%5B1%5D:%0A                    result.append(token%5B1%5D)%0A                    break%0A%0A        if len(result) == 2:%0A            return result%0A        return None%0A%0A    @classmethod%0A    def find_name_by_kanji(cls, kanji):%0A        return cls.find_name_by_index(kanji, 0)%0A%0A    @classmethod%0A    def find_name_by_hiragana(cls, hiragana):%0A        return cls.find_name_by_index(hiragana, 1)%0A%0A    @classmethod%0A    def find_name_by_katakana(cls, katakana):%0A        return cls.find_name_by_index(katakana, 2)%0A

Add find by name functions.