Class: ChineseFaker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/chinese_faker.rb

Direct Known Subclasses

Address, Job, Name

Class Method Summary collapse

Class Method Details

.fetch(key) ⇒ Object



24
25
26
27
28
29
# File 'lib/chinese_faker.rb', line 24

def fetch(key)
  fetched = I18n.translate("chinese_faker.#{key}")
  items = fetched[0].split

  return items[rand(items.length)]
end

.parse(key, with_title = false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chinese_faker.rb', line 12

def parse(key, with_title = false)
  parsed = []

  I18n.translate("chinese_faker.#{key}").each do |format|
    name = format.split
    parsed << name.map { |str| fetch("name.#{str[str.index('{') + 1, str.index('}') - 2]}") }
                  .join
  end

  return with_title ? parsed[0] : parsed[1]
end