Class: Faker::Science

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/science.rb

Constant Summary collapse

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

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.elementString

Produces the name of a element.

Examples:

Faker::Science.element #=> "Carbon"

Returns:

  • (String)

Available since:

  • 1.8.5



56
57
58
# File 'lib/faker/default/science.rb', line 56

def element
  fetch('science.element')
end

.element_stateString

Produces the state of an element.

Examples:

Faker::Science.element_state #=> "Liquid"

Returns:

  • (String)

Available since:

  • next



82
83
84
# File 'lib/faker/default/science.rb', line 82

def element_state
  fetch('science.element_state')
end

.element_subcategoryString

Produces the subcategory of an element.

Examples:

Faker::Science.element_subcategory #=> "Reactive nonmetal"

Returns:

  • (String)

Available since:

  • next



95
96
97
# File 'lib/faker/default/science.rb', line 95

def element_subcategory
  fetch('science.element_subcategory')
end

.element_symbolString

Produces the symbol of an element.

Examples:

Faker::Science.element_symbol #=> "Pb"

Returns:

  • (String)

Available since:

  • 1.9.0



69
70
71
# File 'lib/faker/default/science.rb', line 69

def element_symbol
  fetch('science.element_symbol')
end

.modifierString

Produces a scientifically sounding word

Examples:

Faker::Science.modifier #=> "Quantum"
Faker::Science.modifier #=> "Superconductive"

Returns:

  • (String)

Available since:

  • next



122
123
124
# File 'lib/faker/default/science.rb', line 122

def modifier
  fetch('science.modifier')
end

.science(*branches) ⇒ String

Produces a name of a science You can optionally filter by specifying one or more of the following: ‘:empirical, :formal, :natural, :social, :basic, :applied`

Examples:

Faker::Science.science #=> "Space science"
Faker::Science.science(:natural, :applied) #=> "Engineering"
Faker::Science.science(:formal, :applied) #=> "Computer Science"

Parameters:

  • branches (Array<Symbol>)

Returns:

  • (String)

Raises:

  • (ArgumentError)

See Also:

Available since:

  • next



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/faker/default/science.rb', line 31

def science(*branches)
  selected = BRANCHES.values.flatten.uniq
  branches.each do |branch|
    selected &= BRANCHES[branch] if BRANCHES.key? branch
  end

  raise ArgumentError, 'Filters do not match any sciences' if selected.empty?

  sciences = []
  selected.each do |branch|
    sciences += translate("faker.science.branch.#{branch}")
  end

  sample(sciences)
end

.scientistString

Produces the name of a scientist.

Examples:

Faker::Science.scientist #=> "Isaac Newton"

Returns:

  • (String)

Available since:

  • 1.8.5



108
109
110
# File 'lib/faker/default/science.rb', line 108

def scientist
  fetch('science.scientist')
end

.tool(simple: false) ⇒ String

Produces the name of a scientific tool. By default it uses a science word modifier to generate more diverse data, which can be disabled.

Examples:

Faker::Science.tool #=> "Superconductive Microcentrifuge"
Faker::Science.tool #=> "Portable Cryostat"
Faker::Science.tool #=> "Quantum Spectrophotometer"
Faker::Science.tool(simple: true) #=> "Microcentrifuge"

Parameters:

  • simple (Boolean) (defaults to: false)

    Whether to generate simple realistic tool names, (no Q-word).

Returns:

  • (String)

Available since:

  • next



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/faker/default/science.rb', line 140

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

  "#{modifier} #{tool}"
end