Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more science examples #2369

Merged
merged 7 commits into from Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 82 additions & 0 deletions lib/faker/default/science.rb
Expand Up @@ -3,6 +3,47 @@
module Faker
class Science < Base
class << self
BRANCHES = {
empirical: %i[empirical_natural_basic empirical_natural_applied empirical_social_basic empirical_social_applied],
formal: %i[formal_basic formal_applied],
natural: %i[empirical_natural_basic empirical_natural_applied],
social: %i[empirical_social_basic empirical_social_applied],
basic: %i[empirical_natural_basic empirical_social_basic formal_basic],
applied: %i[empirical_natural_applied empirical_social_applied formal_applied]
}.freeze
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved

##
# Produces a name of a science
# You can optionally filter by specifying one or more of the following:
# `:empirical, :formal, :natural, :social, :basic, :applied`
# @see https://en.wikipedia.org/wiki/Science#Branches_of_science
# @see Faker::Educator.subject
#
# @param branches [Array<Symbol>]
# @return [String]
#
# @example
# Faker::Science.science #=> "Space science"
# Faker::Science.science(:natural, :applied) #=> "Engineering"
# Faker::Science.science(:formal, :applied) #=> "Computer Science"
#
# @faker.version 2.18.1
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved
def science(*branches)
selected = BRANCHES.values.flatten.uniq
branches.each do |branch|
selected &= BRANCHES[branch] if BRANCHES.key? branch
end
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved

raise ArgumentError, 'Filters do not match any sciences' if selected.empty?
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved

sciences = []
selected.each do |branch|
sciences += translate("faker.science.branch.#{branch}")
end
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved

sample(sciences)
end

##
# Produces the name of a element.
#
Expand Down Expand Up @@ -67,6 +108,47 @@ def element_subcategory
def scientist
fetch('science.scientist')
end

##
# Produces a scientifically sounding word
#
# @return [String]
#
# @example
# Faker::Science.modifier #=> "Quantum"
# Faker::Science.modifier #=> "Superconductive"
#
# @faker.version 2.18.1
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved
def modifier
fetch('science.modifier')
end

##
# Produces the name of a scientific tool.
# Optionally it can generate tools with a science word modifier that sound more fancy.
#
# @param simple [Boolean] Whether to generate fancy non-realistic tool names, using the Q-word for example.
# @return [String]
#
# @example
# Faker::Science.tool #=> "Superconductive Microcentrifuge"
# Faker::Science.tool #=> "Portable Cryostat"
# Faker::Science.tool #=> "Quantum Spectrophotometer"
# Faker::Science.tool(simple: true) #=> "Microcentrifuge"
#
# @faker.version 2.18.1
def tool(simple: false)
tool = fetch('science.tool')
return tool if simple

# Makes sure the modifier are different
loop do
modifier = self.modifier
break unless tool.start_with?(modifier)
end
itay-grudev marked this conversation as resolved.
Show resolved Hide resolved

"#{modifier} #{tool}"
end
end
end
end
126 changes: 126 additions & 0 deletions lib/locales/en/science.yml
@@ -1,6 +1,38 @@
en:
faker:
science:
branch:
empirical_natural_basic:
- Physics
- Chemistry
- Biology
- Earth Science
- Space Science
empirical_natural_applied:
- Engineering
- Agricultural Science
- Medicine
- Materials Science
empirical_social_basic:
- Antropology
- Economics
- Political Science
- Human Geography
- Psychology
- Sociology
empirical_social_applied:
- Business Administration
- Public Policy
- Marketing
- Law
- Pedagogy
- International Development
formal_basic:
- Logic
- Mathematics
- Statistics
formal_applied:
- Computer Science
element:
- Actinium
- Aluminum
Expand Down Expand Up @@ -255,6 +287,49 @@ en:
- Reactive nonmetal
- Transition metal
- Unknown chemical properties
modifier:
- Quantum
- Laser
- Radio
- Vacuum
- Gas
- Solid
- Liquid
- Fluid
- Microfluidic
- Mass
- Gamma
- X-ray
- Electon
- Proton
- Subatomic
- UV
- Visual
- Infrared
- Supercooled
- Superconductive
- Mobile
- Portable
- Stationary
- Inverted
- Continuous
- Luminescence
- Vibration
- Scanning
- Linear
- Circular
- Monofocal
- Confocal
- Trifocal
- Thermal
- Small
- Large
- Polar
- Conductive
- Semiconductive
- Non-conductive
- Particle
- Microparticle
scientist:
- Albert Einstein
- Albrecht von Haller
Expand Down Expand Up @@ -356,3 +431,54 @@ en:
- William Bayliss
- William Harvey
- William Herschel
tool:
- Microscope
- Stereomicroscope
- Laser
- Interferometer
- Spectrophotometer
- Spectrometer
- Mass Spectrometer
- NMR Spectrometer
- Homogeniser
- PCR
- NMR
- SDR
- Electrophoresis
- Simulator
- Centrifuge
- Microcentrifuge
- Transducer
- Calorimeter
- Glucometers
- Bioreactor
- Telescope
- Autoclave
- Microwave
- Computer
- Supercomputer
- Analyzer
- Imager
- Fumehood
- Cleanroom
- Mastersizer
- Accelerator
- Microphone
- Fluorimeter
- 3D Scanner
- Data Logger
- Freezer
- Furnace
- Synthesiser
- Reflector
- Cryostat
- Diffractometer
- Manifold
- Pump
- Incubator
- Regulator
- Sonicator
- Chromatographer
- Viscometer
- Generator
- Reactor
28 changes: 28 additions & 0 deletions test/faker/default/test_faker_science.rb
Expand Up @@ -7,6 +7,26 @@ def setup
@tester = Faker::Science
end

def test_science
assert @tester.science.match(/\w+/)
assert @tester.science(:empirical).match(/\w+/)
assert @tester.science(:formal).match(/\w+/)
assert @tester.science(:natural).match(/\w+/)
assert @tester.science(:social).match(/\w+/)
assert @tester.science(:basic).match(/\w+/)
assert @tester.science(:applied).match(/\w+/)
assert @tester.science(:empirical, :natural).match(/\w+/)
assert @tester.science(:empirical, :social).match(/\w+/)
assert @tester.science(:empirical, :natural, :basic).match(/\w+/)
assert @tester.science(:empirical, :natural, :applied).match(/\w+/)
assert @tester.science(:empirical, :social, :basic).match(/\w+/)
assert @tester.science(:empirical, :social, :applied).match(/\w+/)
assert @tester.science(:empirical, :basic).match(/\w+/)
assert @tester.science(:empirical, :applied).match(/\w+/)
assert @tester.science(:formal, :basic).match(/\w+/)
assert @tester.science(:formal, :applied).match(/\w+/)
end

def test_element
assert @tester.element.match(/\w+/)
end
Expand All @@ -26,4 +46,12 @@ def test_element_subcategory
def test_scientist
assert @tester.scientist.match(/\w+/)
end

def test_modifier
assert @tester.modifier.match(/\w+/)
end

def test_tool
assert @tester.tool.match(/\w+/)
end
end