1
0
mirror of https://github.com/askn/faker.git synced 2023-08-10 21:13:01 +03:00
This commit is contained in:
Aşkın Gedik 2016-01-06 14:21:35 +02:00
parent dc3095f20c
commit dd0be570be
9 changed files with 74 additions and 42 deletions

View File

@ -28,7 +28,7 @@ Faker::Address.city
Faker::Address.street_name
Faker::Address.street_address
Faker::Address.secondary_address
Faker::Address.building_number
Faker::Address.zip_code
Faker::Address.postcode
@ -55,12 +55,13 @@ Faker::Company.suffix
```crystal
Faker::Internet.email
Faker::Internet.email('Nancy')
Faker::Internet.email("Nancy")
Faker::Internet.free_email
Faker::Internet.free_email('Nancy')
Faker::Internet.free_email("Nancy")
Faker::Internet.safe_email
Faker::Internet.safe_email("Nancy")
Faker::Internet.user_name
Faker::Internet.user_name('Nancy')
Faker::Internet.user_name("Nancy")
Faker::Internet.domain_name
Faker::Internet.domain_word
@ -74,18 +75,26 @@ Faker::Internet.ip_v4_address
```crystal
Faker::Lorem.words
Faker::Lorem.words(4)
Faker::Lorem.words(4, true)
Faker::Lorem.characters
Faker::Lorem.characters(10)
Faker::Lorem.sentence
Faker::Lorem.sentence(3)
Faker::Lorem.sentence(3, true)
Faker::Lorem.sentences
Faker::Lorem.sentences(1)
Faker::Lorem.sentences(1, true)
Faker::Lorem.paragraph
Faker::Lorem.paragraph(2)
Faker::Lorem.paragraph(2, true)
Faker::Lorem.paragraphs
Faker::Lorem.paragraphs(1)
Faker::Lorem.paragraphs(1, true)
```
### Faker::Name
@ -110,7 +119,7 @@ Faker::PhoneNumber.phone_number
1. Fork it ( https://github.com/askn/faker/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
3. Commit your changes (git commit -am "Add some feature")
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request

View File

@ -6,7 +6,7 @@ puts Faker::Address.city
puts Faker::Address.street_name
puts Faker::Address.street_address
puts Faker::Address.secondary_address
puts Faker::Address.building_number
puts Faker::Address.zip_code
puts Faker::Address.postcode
@ -24,6 +24,8 @@ puts "\n### Faker::Company\n\n"
puts Faker::Company.name
puts Faker::Company.suffix
puts Faker::Company.catch_phrase
puts Faker::Company.bs
puts "\n\t### Faker::Internet\n\n"
@ -31,6 +33,8 @@ puts Faker::Internet.email
puts Faker::Internet.email("Nancy")
puts Faker::Internet.free_email
puts Faker::Internet.free_email("Nancy")
puts Faker::Internet.safe_email
puts Faker::Internet.safe_email("Nancy")
puts Faker::Internet.user_name
puts Faker::Internet.user_name("Nancy")
@ -46,6 +50,9 @@ puts "\n\t### Faker::Lorem\n\n"
puts Faker::Lorem.words
puts Faker::Lorem.words(4)
puts Faker::Lorem.characters
puts Faker::Lorem.characters(10)
puts Faker::Lorem.sentence
puts Faker::Lorem.sentence(3)

View File

@ -3,11 +3,11 @@ require "./faker/*"
module Faker
def self.numerify(number_string)
number_string.gsub(/#/) { rand(10).to_s }
number_string.sub(/#/) { (rand(9) + 1).to_s }.gsub(/#/) { rand(10).to_s }
end
def self.letterify(letter_string)
letter_string.gsub(/\?/) { ("a".."z").to_a.sample }
letter_string.gsub(/\?/) { ("A".."Z").to_a.sample }
end
def self.bothify(string)

View File

@ -41,11 +41,15 @@ module Faker
Faker.numerify(Faker.fetch(Data["address"]["secondary_address"]))
end
def self.building_number
Faker.bothify(Faker.fetch(Data["address"]["building_number"]))
end
def self.postcode
Faker.bothify([
->{ "??# #??" },
->{ "??## #??" },
].sample.call).upcase
].sample.call)
end
def self.latitude

View File

@ -8,6 +8,14 @@ module Faker
Faker.fetch(Data["company"]["suffix"])
end
def self.catch_phrase
[Faker.fetch(Data["company"]["buzzword_1"]), Faker.fetch(Data["company"]["buzzword_2"]), Faker.fetch(Data["company"]["buzzword_3"])].join(" ")
end
def self.bs
[Faker.fetch(Data["company"]["bs_1"]), Faker.fetch(Data["company"]["bs_2"]), Faker.fetch(Data["company"]["bs_3"])].join(" ")
end
Formats = [
->{ [Name.last_name, suffix].join(' ') },
->{ [Name.last_name, Name.last_name].join('-') },

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,10 @@ module Faker
[user_name(name), Faker.fetch(Data["internet"]["free_email"])].join("@")
end
def self.safe_email(name = nil)
[user_name(name), "example." + %w(org com net).shuffle.first].join("@")
end
def self.user_name(name = nil)
return name.scan(/\w+/).shuffle.map(&.[0]).join(%w(. _).sample).downcase if name
[
@ -34,10 +38,10 @@ module Faker
def self.ip_v4_address
[
(0..255).to_a.sample,
(0..255).to_a.sample,
(0..255).to_a.sample,
(0..255).to_a.sample,
(2..254).to_a.sample,
(2..254).to_a.sample,
(2..254).to_a.sample,
(2..254).to_a.sample,
].join('.')
end
end

View File

@ -1,31 +1,38 @@
module Faker
# Based on Perl"s Text::Lorem
class Lorem
def self.words(num = 3)
def self.characters(char_count = 255)
chars = ("a".."z").to_a + (0..9).to_a
Array(String).new(char_count < 0 ? 0 : char_count, "").map { chars.sample }.join("")
end
def self.words(num = 3, supplemental = false)
words = Data["lorem"]["words"] as Array
words += (Data["lorem"]["supplemental"] as Array) if supplemental
words.shuffle[0, num]
end
def self.sentence(word_count = 4)
words(word_count + rand(6)).join(" ").capitalize + "."
def self.sentence(word_count = 4, supplemental = false)
words(word_count + rand(6), supplemental).join(" ").capitalize + "."
end
def self.sentences(sentence_count = 3)
def self.sentences(sentence_count = 3, supplemental = false)
([] of String).tap do |sentences|
1.upto(sentence_count) do
sentences << sentence
sentences << sentence(3, supplemental)
end
end
end
def self.paragraph(sentence_count = 3)
sentences(sentence_count + rand(3)).join(" ")
def self.paragraph(sentence_count = 3, supplemental = false)
sentences(sentence_count + rand(3), supplemental).join(" ")
end
def self.paragraphs(paragraph_count = 3)
def self.paragraphs(paragraph_count = 3, supplemental = false)
([] of String).tap do |paragraphs|
1.upto(paragraph_count) do
paragraphs << paragraph
paragraphs << paragraph(3, supplemental)
end
end
end

View File

@ -15,24 +15,6 @@ module Faker
Faker.fetch(title["descriptor"]) + " " + Faker.fetch(title["level"]) + " " + Faker.fetch(title["job"])
end
def self.catch_phrase
[
["Adaptive", "Advanced", "Ameliorated", "Assimilated", "Automated", "Balanced", "Business-focused", "Centralized", "Cloned", "Compatible", "Configurable", "Cross-group", "Cross-platform", "Customer-focused", "Customizable", "Decentralized", "De-engineered", "Devolved", "Digitized", "Distributed", "Diverse", "Down-sized", "Enhanced", "Enterprise-wide", "Ergonomic", "Exclusive", "Expanded", "Extended", "Face to face", "Focused", "Front-line", "Fully-configurable", "Function-based", "Fundamental", "Future-proofed", "Grass-roots", "Horizontal", "Implemented", "Innovative", "Integrated", "Intuitive", "Inverse", "Managed", "Mandatory", "Monitored", "Multi-channelled", "Multi-lateral", "Multi-layered", "Multi-tiered", "Networked", "Object-based", "Open-architected", "Open-source", "Operative", "Optimized", "Optional", "Organic", "Organized", "Persevering", "Persistent", "Phased", "Polarised", "Pre-emptive", "Proactive", "Profit-focused", "Profound", "Programmable", "Progressive", "Public-key", "Quality-focused", "Reactive", "Realigned", "Re-contextualized", "Re-engineered", "Reduced", "Reverse-engineered", "Right-sized", "Robust", "Seamless", "Secured", "Self-enabling", "Sharable", "Stand-alone", "Streamlined", "Switchable", "Synchronised", "Synergistic", "Synergized", "Team-oriented", "Total", "Triple-buffered", "Universal", "Up-sized", "Upgradable", "User-centric", "User-friendly", "Versatile", "Virtual", "Visionary", "Vision-oriented"].sample,
["24 hour", "24/7", "3rd generation", "4th generation", "5th generation", "6th generation", "actuating", "analyzing", "assymetric", "asynchronous", "attitude-oriented", "background", "bandwidth-monitored", "bi-directional", "bifurcated", "bottom-line", "clear-thinking", "client-driven", "client-server", "coherent", "cohesive", "composite", "context-sensitive", "contextually-based", "content-based", "dedicated", "demand-driven", "didactic", "directional", "discrete", "disintermediate", "dynamic", "eco-centric", "empowering", "encompassing", "even-keeled", "executive", "explicit", "exuding", "fault-tolerant", "foreground", "fresh-thinking", "full-range", "global", "grid-enabled", "heuristic", "high-level", "holistic", "homogeneous", "human-resource", "hybrid", "impactful", "incremental", "intangible", "interactive", "intermediate", "leading edge", "local", "logistical", "maximized", "methodical", "mission-critical", "mobile", "modular", "motivating", "multimedia", "multi-state", "multi-tasking", "national", "needs-based", "neutral", "next generation", "non-volatile", "object-oriented", "optimal", "optimizing", "radical", "real-time", "reciprocal", "regional", "responsive", "scalable", "secondary", "solution-oriented", "stable", "static", "systematic", "systemic", "system-worthy", "tangible", "tertiary", "transitional", "uniform", "upward-trending", "user-facing", "value-added", "web-enabled", "well-modulated", "zero administration", "zero defect", "zero tolerance"].sample,
["ability", "access", "adapter", "algorithm", "alliance", "analyzer", "application", "approach", "architecture", "archive", "artificial intelligence", "array", "attitude", "benchmark", "budgetary management", "capability", "capacity", "challenge", "circuit", "collaboration", "complexity", "concept", "conglomeration", "contingency", "core", "customer loyalty", "database", "data-warehouse", "definition", "emulation", "encoding", "encryption", "extranet", "firmware", "flexibility", "focus group", "forecast", "frame", "framework", "function", "functionalities", "Graphic Interface", "groupware", "Graphical User Interface", "hardware", "help-desk", "hierarchy", "hub", "implementation", "info-mediaries", "infrastructure", "initiative", "installation", "instruction set", "interface", "internet solution", "intranet", "knowledge user", "knowledge base", "local area network", "leverage", "matrices", "matrix", "methodology", "middleware", "migration", "model", "moderator", "monitoring", "moratorium", "neural-net", "open architecture", "open system", "orchestration", "paradigm", "parallelism", "policy", "portal", "pricing structure", "process improvement", "product", "productivity", "project", "projection", "protocol", "secured line", "service-desk", "software", "solution", "standardization", "strategy", "structure", "success", "superstructure", "support", "synergy", "system engine", "task-force", "throughput", "time-frame", "toolset", "utilisation", "website", "workforce"].sample,
].join(" ")
end
# When a straight answer won't do, BS to the rescue!
# Wordlist from http://dack.com/web/bullshit.html
def self.bs
[
["implement", "utilize", "integrate", "streamline", "optimize", "evolve", "transform", "embrace", "enable", "orchestrate", "leverage", "reinvent", "aggregate", "architect", "enhance", "incentivize", "morph", "empower", "envisioneer", "monetize", "harness", "facilitate", "seize", "disintermediate", "synergize", "strategize", "deploy", "brand", "grow", "target", "syndicate", "synthesize", "deliver", "mesh", "incubate", "engage", "maximize", "benchmark", "expedite", "reintermediate", "whiteboard", "visualize", "repurpose", "innovate", "scale", "unleash", "drive", "extend", "engineer", "revolutionize", "generate", "exploit", "transition", "e-enable", "iterate", "cultivate", "matrix", "productize", "redefine", "recontextualize"].sample,
["clicks-and-mortar", "value-added", "vertical", "proactive", "robust", "revolutionary", "scalable", "leading-edge", "innovative", "intuitive", "strategic", "e-business", "mission-critical", "sticky", "one-to-one", "24/7", "end-to-end", "global", "B2B", "B2C", "granular", "frictionless", "virtual", "viral", "dynamic", "24/365", "best-of-breed", "killer", "magnetic", "bleeding-edge", "web-enabled", "interactive", "dot-com", "sexy", "back-end", "real-time", "efficient", "front-end", "distributed", "seamless", "extensible", "turn-key", "world-class", "open-source", "cross-platform", "cross-media", "synergistic", "bricks-and-clicks", "out-of-the-box", "enterprise", "integrated", "impactful", "wireless", "transparent", "next-generation", "cutting-edge", "user-centric", "visionary", "customized", "ubiquitous", "plug-and-play", "collaborative", "compelling", "holistic", "rich"].sample,
["synergies", "web-readiness", "paradigms", "markets", "partnerships", "infrastructures", "platforms", "initiatives", "channels", "eyeballs", "communities", "ROI", "solutions", "e-tailers", "e-services", "action-items", "portals", "niches", "technologies", "content", "vortals", "supply-chains", "convergence", "relationships", "architectures", "interfaces", "e-markets", "e-commerce", "systems", "bandwidth", "infomediaries", "models", "mindshare", "deliverables", "users", "schemas", "networks", "applications", "metrics", "e-business", "functionalities", "experiences", "web services", "methodologies"].sample,
].join(" ")
end
Formats = [
->{ [Name.prefix, Name.first_name, Name.last_name] },
->{ [Name.first_name, Name.last_name, Name.suffix] },