random_data_despegar 2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,121 @@
1
+ module RandomDataDespegar
2
+ module InvoiceData
3
+
4
+ def invoice_data_for(site)
5
+ site ||= "AR"
6
+ self.send("generate_invoice_data_#{site.downcase}")
7
+ end
8
+
9
+ private
10
+ def generate_invoice_data_cr
11
+ {
12
+ :pf => {
13
+ :cedula => Random.id_for("cr"),
14
+ :nite => Random.number_with_size(20),
15
+ :consumidor_final => Random.number_with_size(12)
16
+ },
17
+ :pj => "3234567890"
18
+ }
19
+ end
20
+
21
+ def generate_invoice_data_ec
22
+ {
23
+ :pf => {
24
+ :cedula => Random.id_for("ec"),
25
+ :ruc => "1790085783001",
26
+ },
27
+ :pj => "1760001040001"
28
+ }
29
+ end
30
+
31
+ def generate_invoice_data_pa
32
+ {
33
+ :pf => {
34
+ :cedula => Random.id_for("pa"),
35
+ :ruc => "00001010200641034620",
36
+ :pasaporte => Random.alphanumeric_with_size(20)
37
+ },
38
+ :pj => Random.alphanumeric_with_size(20)
39
+ }
40
+ end
41
+
42
+ def generate_invoice_data_pe
43
+ {
44
+ :pf => {
45
+ :cedula => Random.id_for("pe"),
46
+ :ruc => "00001010200641034620",
47
+ :pasaporte => Random.alphanumeric_with_size(20)
48
+ },
49
+ :pj => "00001010200641034620"
50
+ }
51
+ end
52
+
53
+ def generate_invoice_data_ve
54
+ {
55
+ :pf => {
56
+ :cedula => 12345678901234567890,
57
+ },
58
+ :pj => "E300004930"
59
+ }
60
+ end
61
+
62
+ def generate_invoice_data_mx
63
+ {
64
+ :pf => {:cedula => "VECJ880326XXX"},
65
+ :pj => "ABC680524P76"
66
+ }
67
+ end
68
+
69
+ def generate_invoice_data_co
70
+ {
71
+ :pf => {
72
+ :cedula => Random.id_for("co"),
73
+ :nit => "8603242181",
74
+ :pasaporte => Random.alphanumeric_with_size(20)
75
+ },
76
+ :pj => "8063242183"
77
+ }
78
+ end
79
+
80
+ def generate_invoice_data_cl
81
+ {
82
+ :pf => {
83
+ :cedula => Random.id_for("cl"),
84
+ :run => Random.id_for("cl"),
85
+ :pasaporte => "20222222223"
86
+ },
87
+ :pj => "306869574"
88
+ }
89
+ end
90
+
91
+ def generate_invoice_data_ar
92
+ {
93
+ :pf => {
94
+ :cedula => Random.id_for("ar"),
95
+ :cuil => Random.argentinean_cuil
96
+ },
97
+ :pj => "30708967986"
98
+ }
99
+ end
100
+
101
+ def generate_invoice_data_br
102
+ {
103
+ :pf => {
104
+ :cedula => Random.id_for("br"),
105
+ :cep => cep,
106
+ :cpf => Random.id_for("br")
107
+ },
108
+ :pj => {
109
+ :cpnj => cpnj,
110
+ :inscripcion_municipal => "06091911"
111
+ }
112
+ }
113
+ end
114
+
115
+
116
+
117
+ def method_missing(m, *args, &block)
118
+ puts "#{m} is not implemented here -- use a valid site (:site => 'AR')"
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,143 @@
1
+ # coding:utf-8
2
+
3
+ module RandomDataDespegar
4
+
5
+ # Defines methods to return random location data.
6
+
7
+ module Locations
8
+
9
+
10
+ trees = %w( Acacia Beech Birch Cedar Cherry Chestnut Elm Larch Laurel
11
+ Linden Maple Oak Pine Rose Walnut Willow)
12
+ people = %w( Adams Franklin Jackson Jefferson Lincoln
13
+ Madison Washington Wilson)
14
+ people_uk = %w( Churchill Tyndale Latimer Cranmer )
15
+ places = %w( Highland Hill Park Woodland Sunset Virginia)
16
+ numbers = %w( 1st 2nd 4th 5th 34th 42nd )
17
+ @@streetnames = trees + people + places + numbers
18
+
19
+ @@street_types = %w(St Ave Rd Blvd Trl Ter Rdg Pl Pkwy Ct Circle)
20
+
21
+ # Returns the first line of a US maiiling address (street number, street name, street type)
22
+ #
23
+ # Example:
24
+ #
25
+ #Random.address_line_1 = "24317 Jefferson Blvd"
26
+
27
+ def address_line_1
28
+ "#{rand(40000)} #{@@streetnames.rand} #{@@street_types.rand}"
29
+ end
30
+
31
+ alias :us_address_line_1 :address_line_1
32
+
33
+ @@line2types = ["Apt", "Bsmt", "Bldg", "Dept", "Fl", "Frnt", "Hngr", "Lbby", "Lot", "Lowr", "Ofc", "Ph", "Pier", "Rear", "Rm", "Side", "Slip", "Spc", "Stop", "Ste", "Trlr", "Unit", "Uppr"]
34
+
35
+ # Returns the first line of a US maiiling address (street number, street name, street type)
36
+ #
37
+ # Example:
38
+ #
39
+ #Random.address_line_1 = "24317 Jefferson Blvd"
40
+
41
+ def address_line_2
42
+ "#{@@line2types.rand} #{rand(999)}"
43
+ end
44
+
45
+ # Returns a random 5-digit string, not guaranteed to be a legitimate zip code.
46
+ # Legal zip codes can have leading zeroes and thus they need to be strings.
47
+
48
+ def zipcode
49
+ "%05d" % rand(99999)
50
+ end
51
+
52
+ # Returns brazilian cep
53
+ def cep
54
+ %w{13301611 49085120 64205250 68040692}.sample
55
+ end
56
+
57
+ # Returns brazilian cpnj
58
+ def cpnj
59
+ %w{60173083000142 29829357000169 46663579000173 65645108000187 99572792000136}.sample
60
+ end
61
+
62
+ # Returns a string providing something in the general form of a UK post code. Like the zip codes, this might
63
+ # not actually be valid. Doesn't cover London whose codes are like "SE1".
64
+
65
+ def uk_post_code
66
+ post_towns = %w(BM CB CV LE LI LS KT MK NE OX PL YO)
67
+ # Can't remember any othes at the moment
68
+ number_1 = rand(100).to_s
69
+ number_2 = rand(100).to_s
70
+ # Easier way to do this?
71
+ letters = ("AA".."ZZ").to_a.rand
72
+
73
+ return "#{post_towns.rand}#{number_1} #{number_2}#{letters}"
74
+ end
75
+
76
+ # from technoweenie: http://svn.techno-weenie.net/projects/plugins/us_states/lib/us_states.rb
77
+ @@us_states = [["Alaska", "AK"], ["Alabama", "AL"], ["Arkansas", "AR"], ["Arizona", "AZ"],
78
+ ["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["District of Columbia", "DC"],
79
+ ["Delaware", "DE"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Iowa", "IA"],
80
+ ["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Kansas", "KS"], ["Kentucky", "KY"],
81
+ ["Louisiana", "LA"], ["Massachusetts", "MA"], ["Maryland", "MD"], ["Maine", "ME"], ["Michigan", "MI"],
82
+ ["Minnesota", "MN"], ["Missouri", "MO"], ["Mississippi", "MS"], ["Montana", "MT"], ["North Carolina", "NC"],
83
+ ["North Dakota", "ND"], ["Nebraska", "NE"], ["New Hampshire", "NH"], ["New Jersey", "NJ"],
84
+ ["New Mexico", "NM"], ["Nevada", "NV"], ["New York", "NY"], ["Ohio", "OH"], ["Oklahoma", "OK"],
85
+ ["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"],
86
+ ["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Virginia", "VA"], ["Vermont", "VT"],
87
+ ["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]]
88
+
89
+ # Returns a state 2-character abbreviation
90
+ # Random.state_code = "IL"
91
+
92
+ def state_code
93
+ @@us_states.rand[1]
94
+ end
95
+
96
+ # Returns a full state name
97
+ #Random.state_full = "Texas"
98
+
99
+ def state_full
100
+ @@us_states.rand[0]
101
+ end
102
+
103
+ # from http://siteresources.worldbank.org/DATASTATISTICS/Resources/CLASS.XLS
104
+ @@countries = ["Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia",
105
+ "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan",
106
+ "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon",
107
+ "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Channel Islands", "Chile", "China", "Colombia", "Comoros", "Congo, Dem. Rep.",
108
+ "Congo, Rep.", "Costa Rica", "Côte d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
109
+ "Egypt, Arab Rep.", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Faeroe Islands", "Fiji", "Finland", "France", "French Polynesia",
110
+ "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti",
111
+ "Honduras", "Hong Kong, China", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Rep.", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica",
112
+ "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Dem. Rep.", "Korea, Rep.", "Kuwait", "Kyrgyz Republic", "Lao PDR", "Latvia", "Lebanon", "Lesotho",
113
+ "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao, China", "Macedonia, FYR", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta",
114
+ "Marshall Islands", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Fed. Sts.", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco",
115
+ "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria",
116
+ "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
117
+ "Puerto Rico", "Qatar", "Romania", "Russian Federation", "Rwanda", "Samoa", "San Marino", "São Tomé and Principe", "Saudi Arabia", "Senegal", "Serbia",
118
+ "Seychelles", "Sierra Leone", "Singapore", "Slovak Republic", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "St. Kitts and Nevis",
119
+ "St. Lucia", "St. Vincent and the Grenadines", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Tajikistan", "Tanzania", "Thailand",
120
+ "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
121
+ "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela, RB", "Vietnam", "Virgin Islands (U.S.)", "West Bank and Gaza", "Yemen, Rep.", "Zambia", "Zimbabwe"]
122
+
123
+ # Returns a country name, as listed by the World Bank
124
+ #
125
+ #Random.country = "Kenya"
126
+
127
+ def country
128
+ @@countries.rand
129
+ end
130
+
131
+ @@cities = %w(Midway Mount\ Pleasant Greenwood Franklin Oak Grove Centerville Salem Georgetown Fairview Riverside Rotorua Tauranga Whakatane Taupo Wanganui
132
+ Nababeep Aggeneys Pofadder Polokwane Bela Bela Goukamma Karatara Tswane Prieska Upington Hoopstad Bultfontein Wesselsbron Bothaville Trompsburg
133
+ Henneman Musina Ogies Kgatlahong Tembisa Tekoza Sebokeng Muntaung Umnkomaaz)
134
+
135
+ # Returns a generic city name, with an attempt to have some internationl appeal
136
+ #
137
+ # Random.city = "Tekoza"
138
+
139
+ def city
140
+ @@cities.rand
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,77 @@
1
+ # Methods to create a markov chain from some input text.
2
+
3
+
4
+ module RandomDataDespegar
5
+ class MarkovGenerator
6
+
7
+ def initialize(memory = 1)
8
+ @memory_size = memory
9
+ @table = Hash.new {|h,k| h[k] = {}}
10
+ @state = []
11
+ end
12
+
13
+
14
+ # given the next token of input add it to the
15
+ # table
16
+ def insert(result)
17
+ # puts "insert called with #{result}"
18
+ tabindex = Marshal.dump(@state)
19
+ if @table[tabindex].has_key?(result)
20
+ @table[tabindex][result] += 1
21
+ else
22
+ @table[tabindex][result] = 1
23
+ end
24
+ # puts "table #{@table.inspect}"
25
+ next_state(result)
26
+ end
27
+
28
+ def next_state(result)
29
+ @state.shift if @state.size >= @memory_size
30
+ @state.push(result)
31
+ # puts "@state is #{@state.inspect}"
32
+ end
33
+
34
+ def generate(n=1, clear_state=false)
35
+ @state = [] if clear_state
36
+ results = []
37
+ n.times do
38
+ retry_count = 0
39
+ begin
40
+ result_hash = @table[Marshal.dump(@state)]
41
+ the_keys,the_vals = [],[]
42
+ result_hash.each_pair do |k,v|
43
+ the_keys << k
44
+ the_vals << v
45
+ end
46
+ # get the weighted random value, by index.
47
+ i = the_vals.roulette
48
+ rescue
49
+ # puts "results:#{result_hash.inspect}";
50
+ # puts "keys:#{the_keys.inspect}";
51
+ # puts "vals:#{the_vals.inspect}";
52
+ # puts "state:#{@state.inspect}";
53
+ @state = []
54
+ retry_count += 1
55
+ if retry_count < 5
56
+ retry
57
+ else
58
+ # puts
59
+ # puts "table:#{@table.inspect}";
60
+ raise
61
+ end
62
+ end
63
+ result = the_keys[i]
64
+ # puts "index:#{i.inspect}";
65
+
66
+ next_state(result)
67
+ if block_given?
68
+ yield result
69
+ end
70
+ results << result
71
+ end
72
+ return results
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,108 @@
1
+ module RandomDataDespegar
2
+
3
+ # Methods to create realistic-looking names
4
+ module Names
5
+
6
+ # Returns a random letter
7
+
8
+ def initial
9
+ ('A'..'Z').to_a.rand
10
+ end
11
+
12
+ @@lastnames = %w(ABEL ANDERSON ANDREWS ANTHONY BAKER BROWN BURROWS CLARK CLARKE CLARKSON DAVIDSON DAVIES DAVIS
13
+ DENT EDWARDS GARCIA GRANT HALL HARRIS HARRISON JACKSON JEFFRIES JEFFERSON JOHNSON JONES
14
+ KIRBY KIRK LAKE LEE LEWIS MARTIN MARTINEZ MAJOR MILLER MOORE OATES PETERS PETERSON ROBERTSON
15
+ ROBINSON RODRIGUEZ SMITH SMYTHE STEVENS TAYLOR THATCHER THOMAS THOMPSON WALKER WASHINGTON WHITE
16
+ WILLIAMS WILSON YORKE)
17
+ @@incorporation_types = %w{LLC Inc Inc. Ltd. LP LLP Corp. PLLC}
18
+ @@company_types = %w{Clothier Publishing Computing Consulting Engineering Industries Marketing Manufacturing}
19
+
20
+ # Returns a random company name
21
+ #
22
+ # >> Random.company_name
23
+ #
24
+ # "Harris & Thomas"
25
+
26
+ def companyname
27
+ num = rand(5)
28
+ if num == 0
29
+ num = 1
30
+ end
31
+ final = num.times.collect { @@lastnames.rand.capitalize }
32
+
33
+ if final.count == 1
34
+ "#{final.first} #{@@company_types.rand}, #{@@incorporation_types.rand}"
35
+ else
36
+ incorporation_type = rand(17) % 2 == 0 ? @@incorporation_types.rand : nil
37
+ company_type = rand(17) % 2 == 0 ? @@company_types.rand : nil
38
+ trailer = company_type.nil? ? "" : " #{company_type}"
39
+ trailer << ", #{incorporation_type}" unless incorporation_type.nil?
40
+ "#{final[0..-1].join(', ')} & #{final.last}#{trailer}"
41
+ end
42
+ end
43
+
44
+ alias company_name companyname
45
+ # Returns a random lastname
46
+ #
47
+ # >> Random.lastname
48
+ #
49
+ # "Harris"
50
+
51
+ def lastname
52
+ @@lastnames.rand.capitalize
53
+ end
54
+ alias last_name lastname
55
+
56
+ @@male_first_names = %w(ADAM ANTHONY ARTHUR BRIAN CHARLES CHRISTOPHER DANIEL DAVID DONALD EDGAR EDWARD EDWIN
57
+ GEORGE HAROLD HERBERT HUGH JAMES JASON JOHN JOSEPH KENNETH KEVIN MARCUS MARK MATTHEW
58
+ MICHAEL PAUL PHILIP RICHARD ROBERT ROGER RONALD SIMON STEVEN TERRY THOMAS WILLIAM)
59
+
60
+ @@female_first_names = %w(ALISON ANN ANNA ANNE BARBARA BETTY BERYL CAROL CHARLOTTE CHERYL DEBORAH DIANA DONNA
61
+ DOROTHY ELIZABETH EVE FELICITY FIONA HELEN HELENA JENNIFER JESSICA JUDITH KAREN KIMBERLY
62
+ LAURA LINDA LISA LUCY MARGARET MARIA MARY MICHELLE NANCY PATRICIA POLLY ROBYN RUTH SANDRA
63
+ SARAH SHARON SUSAN TABITHA URSULA VICTORIA WENDY)
64
+
65
+ @@first_names = @@male_first_names + @@female_first_names
66
+
67
+
68
+ # Returns a random firstname
69
+ #
70
+ # >> Random.firstname
71
+ #
72
+ # "Sandra"
73
+
74
+ def firstname
75
+ @@first_names.rand.capitalize
76
+ end
77
+ alias first_name firstname
78
+
79
+
80
+ # Returns a random male firstname
81
+ #
82
+ # >> Random.firstname_male
83
+ #
84
+ # "James"
85
+
86
+ def firstname_male
87
+ @@male_first_names.rand.capitalize
88
+ end
89
+ alias first_name_male firstname_male
90
+
91
+
92
+ # Returns a random female firstname
93
+ #
94
+ # >> Random.firstname_female
95
+ #
96
+ # "Mary"
97
+
98
+ def firstname_female
99
+ @@female_first_names.rand.capitalize
100
+ end
101
+ alias first_name_female firstname_female
102
+
103
+ # Returns a random full name
104
+ def full_name(options = { :initial => false, :gender => nil })
105
+ "#{first_name} #{last_name}"
106
+ end
107
+ end
108
+ end