At this week i start working on porting this Python open source library for Elixir and I ran into some difficulties, because i’m beginner in Elixir.
In Python we can save data (from JSON file) in self.data and work with them.
class Address(object):
def __init__(self, locale='en'):
self.locale = locale
self.data = pull('address.json', self.locale)
def get_city(self):
return self.data["city"]
At this moment i use following method:
def name(gender) do
{:ok, names} = Machiavelli.pull("personal", "names", :en)
Enum.random(names[gender])
end
def surname(gender) do
{:ok, surnames} = Machiavelli.pull("personal", "surnames", :en)
Enum.random(surnames[gender])
end
but it is not good, because we pull data from json after every calling of function
When must be something like:
def name(gender) do
{:ok, names} = Machiavelli.data["names"][gender]
names |> Enum.random
end
def surname(gender) do
{:ok, surnames} = Machiavelli.data["surnames"][gender]
surnames |> Enum.random
end
So, how i can store the data like in example above?
Project located here.