Class: DataMaker::CN::Address::GenerateAddress
- Inherits:
-
Object
- Object
- DataMaker::CN::Address::GenerateAddress
- Defined in:
- lib/data_maker/cn/address.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#district ⇒ Object
Returns the value of attribute district.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#options ⇒ Object
Returns the value of attribute options.
-
#province ⇒ Object
Returns the value of attribute province.
-
#street_address ⇒ Object
Returns the value of attribute street_address.
Instance Method Summary collapse
- #address_string ⇒ Object
- #address_struct ⇒ Object
- #generate ⇒ Object
-
#initialize(*args) ⇒ GenerateAddress
constructor
A new instance of GenerateAddress.
- #postal_code ⇒ Object
Constructor Details
#initialize(*args) ⇒ GenerateAddress
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/data_maker/cn/address.rb', line 36 def initialize(*args) self. = (args.last.is_a?(::Hash) ? args.last : {}).delete_if { |k, v| v.nil? } self.district = [:district] self.city = [:city] self.province = [:province] self.locale = [:locale] || :zh unless .empty? validate end end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
34 35 36 |
# File 'lib/data_maker/cn/address.rb', line 34 def city @city end |
#district ⇒ Object
Returns the value of attribute district.
34 35 36 |
# File 'lib/data_maker/cn/address.rb', line 34 def district @district end |
#locale ⇒ Object
Returns the value of attribute locale.
34 35 36 |
# File 'lib/data_maker/cn/address.rb', line 34 def locale @locale end |
#options ⇒ Object
Returns the value of attribute options.
34 35 36 |
# File 'lib/data_maker/cn/address.rb', line 34 def @options end |
#province ⇒ Object
Returns the value of attribute province.
34 35 36 |
# File 'lib/data_maker/cn/address.rb', line 34 def province @province end |
#street_address ⇒ Object
Returns the value of attribute street_address.
34 35 36 |
# File 'lib/data_maker/cn/address.rb', line 34 def street_address @street_address end |
Instance Method Details
#address_string ⇒ Object
70 71 72 73 |
# File 'lib/data_maker/cn/address.rb', line 70 def address_string generate build_address end |
#address_struct ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/data_maker/cn/address.rb', line 75 def address_struct generate OpenStruct.new(street_address: street_address, city: translate('city', city), district: (translate('district', district) unless district.nil?), province: translate('province', province), postal_code: postal_code ) end |
#generate ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/data_maker/cn/address.rb', line 47 def generate if .empty? # Generate a random address from a province self.province = provinces.sample self.city = province_cities.sample self.district = city_districts.nil? ? nil : city_districts.sample end if [:province] && [:city].nil? && [:district].nil? self.city = province_cities.sample self.district = city_districts.nil? ? nil : city_districts.sample end if [:province].nil? && [:city] && [:district].nil? self.province = city_province self.district = city_districts.nil? ? nil : city_districts.sample end end |
#postal_code ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/data_maker/cn/address.rb', line 85 def postal_code postal_code = nil province_postal_codes = DataMaker::CN::Address::PROVINCE_POSTAL_CODES province_postal_codes.to_set.select do |province_postal_code| p, pc = province_postal_code.split(",") p == province ? postal_code = pc : nil end postal_code end |